Django 1.8创建迁移,但没有任何改变 [英] Django 1.8 creates migration but nothing has changed
问题描述
产品
和费用
。 产品
最近更改了其 unique_together
字段。 费用
没有更改其 unique_together
字段。当我运行 ./ manage.py makemigrations
我得到一个包含两个更改的文件: operations = [
migrations.AlterUniqueTogether(
name ='fee',
unique_together = set([('product','fee_type','content_type','object_id' ,
),
migrations.AlterUniqueTogether(
name ='product',
unique_together = set([('producer','product_type' 'term')]),
),
]
注意它正在改变产品
的唯一的约束约束,这是很好的。但是,它也是为费用
。这是因为数据库中已经存在唯一的一起约束的原因和错误。错误是 django.db.utils.ProgrammingError:relationproduct_fee_product_id_7b033c697cde4424_uniq已经存在
每次运行 ./ manage.py makemigrations
我得到 AlterUniqueTogether
的东西费用
模型,即使我只是简单地评论它,或从文件中删除它们与两次迁移。如何防止 makemigrations
检测到这种不存在的变化?
你可以尝试创建一个仅将费用
模型唯一更改为唯一的迁移,然后使用 - fake
选项应用它
./ manage.py migrate yourapp 00XX_your_migration --fake
/ pre>
在您伪造迁移后,您所创建的任何新迁移都不应包含该更改。
I am having a migration issue with a Django 1.8.2 application. I'm using two models,
Product
andFee
.Product
recently had a change to itsunique_together
field.Fee
had no changes to itsunique_together
field. When I run./manage.py makemigrations
I get a file with two changes: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')]), ), ]
You'll notice it is changing the unique together constraint for
Product
, which is fine. But then it is also doing it forFee
. That causes and error because that unique together constraint already exists in the database. The error isdjango.db.utils.ProgrammingError: relation "product_fee_product_id_7b033c697cde4424_uniq" already exists
Every time I run
./manage.py makemigrations
I get theAlterUniqueTogether
stuff for theFee
model, even if I simply comment it out or remove it from the file with both migrations. How can I preventmakemigrations
from detecting this nonexistent change?解决方案You could try creating a migration that only alters the unique together for the
Fee
model, and then use the--fake
option to apply it./manage.py migrate yourapp 00XX_your_migration --fake
After you've faked the migration, the change should not be included in any new migrations you create.
这篇关于Django 1.8创建迁移,但没有任何改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!