Django 1.8创建迁移,但没有任何改变 [英] Django 1.8 creates migration but nothing has changed

查看:212
本文介绍了Django 1.8创建迁移,但没有任何改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Django 1.8.2应用程序的迁移问题。我使用两种型号,产品费用产品最近更改了其 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 and Fee. Product recently had a change to its unique_together field. Fee had no changes to its unique_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 for Fee. That causes and error because that unique together constraint already exists in the database. The error is django.db.utils.ProgrammingError: relation "product_fee_product_id_7b033c697cde4424_uniq" already exists

Every time I run ./manage.py makemigrations I get the AlterUniqueTogether stuff for the Fee model, even if I simply comment it out or remove it from the file with both migrations. How can I prevent makemigrations 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆