2016-06-11 44 views
0

我将我的烧瓶应用程序部署到heroku中。 当我运行这个命令时,我得到一个错误。如何通过migraions id链接两个迁移并创建线性链以折叠分支?

heroku run python manage.py deploy 

这是错误消息:

raise util.CommandError('Only a single head is supported. The ' alembic.util.CommandError: Only a single head is supported. The script directory has multiple heads (due to branching), which must be resolved by manually editing the revision files to form a linear sequence. Run alembic branches to see the divergence(s).

敖我GOOGLE了它,然后我得到这个:

this happens when you go back to a revision that is not the last and then create a new migration. Now you have two branches, which Alembic cannot handle.Look at how the migration files are chained together through migration ids, you need to create a linear chain to collapse the branches.

但我仍然感到困惑如何解决。 我认为这个问题是由git分支造成的。 (我试图合并两个分支,但没有工作?)

+0

您最有可能在将这些分支合并回主(或您使用的任何分支)之前,在两个不同分支中生成迁移。现在你有两次迁移,声称是在Heroku中运行的最后一个迁移之后运行的迁移。您可以使用['alembic merge'命令](http://alembic.readthedocs.io/en/latest/branches.html#merging-branches)来修复它。 – dirn

回答

0

看起来像你引用了我很久以前在我的一篇博客文章中提到的评论。从那以后,我写了一篇专门讨论解决迁移冲突问题的文章:http://blog.miguelgrinberg.com/post/resolving-database-schema-conflicts

这是在文章中解释的,但基本上必须编辑迁移脚本,以便它们形成线性序列。每个脚本都有一个指向其前任的指针,当有两个或更多具有相同前辈的脚本时,会发生冲突。假设你有B和C的迁移,都以A作为前任。例如:

 --> B 
A __/ 
    \ 
    --> C 

假设您在迁移B,C迁移无法应用,因为它位于不同的分支上。解决冲突的一种可能的方式是在C脚本前身从A更改为B.然后迁移链变为:

A --> B --> C 

所以现在蒸馏器可以从B移至C.

另一种选择,在最近版本的Alembic中支持的是使用merge命令来创建合并迁移。我在文章中简要介绍了这一点,但这不是我的首选解决方案。

+0

非常感谢你。我明白为什么它解决了。 –