0

I deployed my flask app into heroku. When I run this command I get an error.

heroku run python manage.py deploy 

This is the error message:

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).

Ao I googled it,then i got this:

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.

But I'm still confused about how to solve that. I think the problem is caused by git branches. (I tried to merge two branches, but didn't work?)

Håken Lid
  • 22,318
  • 9
  • 52
  • 67
  • You most likely generated migrations in two different branches before merging those branches back into master (or whatever branch you use). Now you have two migrations that claim to be the migration to run after the last one you ran in Heroku. You can use the [`alembic merge` command](http://alembic.readthedocs.io/en/latest/branches.html#merging-branches) to fix it. – dirn Jun 11 '16 at 13:10

1 Answers1

0

Looks like you quoted a comment I made long ago in one of my blog articles. Since then, I have written an article dedicated to the topic of resolving migration conflicts: http://blog.miguelgrinberg.com/post/resolving-database-schema-conflicts

This is explained in the article, but basically, have to edit the migration scripts so that they form a linear sequence. Each script has a pointer to its predecessor, the conflict occurs when you have two or more scripts that have the same predecessor. Say you have migrations B and C, both with A as predecessor. Something like this:

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

Assuming you are at migration B, the C migration cannot be applied because it is on a different branch. One possible way to address the conflict is to change the predecessor in the C script from A to B. Then the migration chain becomes:

A --> B --> C

So now Alembic can move from B to C.

Another option, supported in recent versions of Alembic is to use the merge command to create a merge migration. I cover this briefly in my article as well, but this isn't my preferred solution.

Miguel Grinberg
  • 65,299
  • 14
  • 133
  • 152