2016-06-11 42 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

非常感謝你。我明白爲什麼它解決了。 –