1
比方說,我有這樣的模式:如何用Django重命名模型?
class Foo(models.Model):
name = models.CharField(max_length=255)
我想將它重命名爲Bar
。我應該採取什麼措施?我該如何處理The following content types are stale
提示?
比方說,我有這樣的模式:如何用Django重命名模型?
class Foo(models.Model):
name = models.CharField(max_length=255)
我想將它重命名爲Bar
。我應該採取什麼措施?我該如何處理The following content types are stale
提示?
在我的特殊情況下,它是像這樣:
./manage.py makemigrations
。django_content_type
table。相應地處理它們。檢查您的數據庫以獲取來自Django表的引用。最有可能的,這將是:
my_table-+-django_admin_log
`-auth_permission-+-auth_group_permissions
`-auth_user_user_permissions
在我來說,我沒有記錄在django_admin_log
,auth_group_permissions
,auth_user_user_permissions
。
運行./manage.py migrate
。當它問:
The following content types are stale and need to be deleted:
myapp | foo
Any objects related to these content types by a foreign key will also
be deleted. Are you sure you want to delete these content types?
If you're unsure, answer 'no'.
Type 'yes' to continue, or 'no' to cancel:
你可以回答yes
只有當你有沒有記錄上述三個表中引用記錄foo
表。或者如果失去它們對你來說不是問題。
難道你不能重命名它並運行'./manage.py makemigrations'嗎? – C14L
@ C14L因爲你必須對Django內部有一定的瞭解。看到我的答案。 –