【发布时间】:2015-08-03 06:52:11
【问题描述】:
我遇到了 Django 1.8.2 应用程序的迁移问题。我正在使用两个模型,Product 和 Fee。 Product 最近对其unique_together 字段进行了更改。 Fee 的 unique_together 字段没有变化。当我运行 ./manage.py makemigrations 时,我得到一个包含两个更改的文件:
operations = [
migrations.AlterUniqueTogether(
name='fee',
unique_together=set([('product', 'fee_type', 'content_type', 'object_id', 'activation_date')]),
),
migrations.AlterUniqueTogether(
name='product',
unique_together=set([('producer', 'product_type', 'term')]),
),
]
您会注意到它正在更改 Product 的唯一共同约束,这很好。但它也在为Fee 做这件事。这会导致错误,因为该唯一的共同约束已经存在于数据库中。错误是django.db.utils.ProgrammingError: relation "product_fee_product_id_7b033c697cde4424_uniq" already exists
每次我运行./manage.py makemigrations 时,我都会得到Fee 模型的AlterUniqueTogether 内容,即使我只是简单地将其注释掉或在两次迁移时将其从文件中删除。如何防止makemigrations 检测到这个不存在的更改?
【问题讨论】:
-
你试过
flush和reset -
我没有,没有。我认为我不熟悉这些命令。
-
flush刷新数据库中的数据,reset重置表。 -
我不认为我可以
flush,因为这将完全删除表中的所有数据。而且我在文档中没有看到reset命令。 -
如果你不能
flush,那么你最喜欢的就不会reset。我认为问题出在骄傲 id7b033c697cde4424上。尝试删除或重命名该项目
标签: django django-models django-migrations