简体   繁体   English

修复在 Django1.9 中检测到的冲突迁移

[英]Fix Conflicting migrations detected in Django1.9

I updated django-dynamic-model repository to support Django 1.9.我更新了django-dynamic-model存储库以支持 Django 1.9。 I got this error:我收到此错误:

CommandError: 

Conflicting migrations detected; multiple leaf nodes in the migration
graph: (0001_initial, 0002_auto__add_field_dynamicschemafield_extra in
dynamicmodel).
To fix them run 'python manage.py makemigrations --merge'

After running python manage.py makemigrations --merge , I got another error:运行python manage.py makemigrations --merge ,我遇到了另一个错误:

 File "/local/lib/python2.7/sitepackages/django/core/management/__init__.py",  
line 353, in execute_from_command_line
utility.execute()

 File "/local/lib/python2.7/sitepackages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)

 File 
"/local/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)

File 
"/local/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)

File 
"/local/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 97, in handle
return self.handle_merge(loader, conflicts)

File 
   "/local/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 216, in handle_merge
 raise ValueError("Could not find common ancestor of %s" % migration_names)


 ValueError: Could not find common ancestor of set([u'0001_initial', u'0002_auto__add_field_dynamicschemafield_extra']). 

Help me to find the solution.帮我找到解决办法。

The migrations need to have "straight" dependency chain, ie migration 0003 needs to depend on migration 0002, and 0002 on 0001.迁移需要具有“直”依赖链,即迁移 0003 需要依赖于迁移 0002,而迁移 0002 需要依赖于 0001。

You need to define this in the 0003_third.py like this:您需要在 0003_third.py 中像这样定义它:

class Migration(migrations.Migration):
    dependencies = [
        ('modulename', '0002_second'),
    ]

Seems like you have injected models of other applications.似乎您注入了其他应用程序的模型。

Define TARGET_APP in your migrations, seems like migrations loader can't correctly identify target app.在您的迁移中定义 TARGET_APP,似乎迁移加载程序无法正确识别目标应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM