设置:
姜戈 1.7 | Postgres 9.x
class Buildings(BaseModel):
number = models.CharField(max_length=25)
class TestGeneric(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey()
假设我创建了一个TestGeneric
实例,将它与 a 关联Building
并保存它:
TestGeneric.objects.create(content_object=Building.objects.first())
现在我重命名Buildings
为Building
并运行makemigrations
. 提示我Did you rename the app.Buildings model to Building? [y/N]
我选择是。然后我运行migrate
并得到:
The following content types are stale and need to be deleted:
app | buildings
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'.
无论我回答什么,Django 都会自动在django_content_type
其中创建一个新行building
作为名称和标签。有没有办法重命名,ContentType
这样我的所有 TestGeneric 行都不会被吹走?