【发布时间】:2017-01-08 10:14:52
【问题描述】:
我想摆脱运行迁移时收到的以下消息:
The following content types are stale and need to be deleted:
appname | modelname
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?
在迁移中对删除或不删除的决定进行编码似乎更简洁。
作为迁移的一部分,检测和删除陈旧 ContentType 的最简单方法是什么?如果 ContentTypes 为created automatically,为什么不自动完成?
【问题讨论】:
-
如果 generic relations 中使用了内容类型,删除它们将触发这些模型中外键的
on_delete操作,并可能导致数据丢失——这是任何自动化操作都应该避免的费用。创建内容类型不会导致数据丢失,所以自动创建是安全的。 -
无法检测内容类型是否用于泛型关系?
标签: django django-models django-migrations