I've got an application and I wanted to create a new migration for it today. When I run
$ alembic revision -m "__name__"
I got a message
Only a single head is supported. The script directory has multiple heads (due branching), which must be resolved by manually editing the revision files to form a linear sequence.
Run `alembic branches` to see the divergence(s).
Running
alembic branches
gives nothing
I'm new to alembic. There are 2 developers working on this app and we have 2 git branches - master & develop (I'm not sure if this have anything to do with it).
Any clue on what is this about?
This issue happens when two alembic migrations are branched from the same migration. Usually, this happens when multiple people are making schema changes. To fix it you just have to adjust thedown_revision
of your migration to be that of the latest one. Running alembic history
shows us this:
2f4682466279 -> f34e92e9dc54 (head), Fifth revision (on a separate branch)
2f4682466279 -> f673ac37b34a (head), Fifth revision (local)
2dc9337c3987 -> 2f4682466279, Fourth revision
0fa2aed0866a -> 2dc9337c3987, Third revision
22af4a75cf06 -> 0fa2aed0866a, Second revision
9a8942e953eb -> 22af4a75cf06, First revision
You can see that one of the Fifth revisions was made locally and it's downstream revision is2f4682466279
but whoever made the other Fifth revision got the same downstream revision too.
Go into one of the Fifth revision files and update down_revision
variable to reference the other Fifth revision, like this:
f673ac37b34a -> f34e92e9dc54 (head), Fifth revision (on a separate branch)
2f4682466279 -> f673ac37b34a, Fifth revision (local)
2dc9337c3987 -> 2f4682466279, Fourth revision
0fa2aed0866a -> 2dc9337c3987, Third revision
22af4a75cf06 -> 0fa2aed0866a, Second revision
9a8942e953eb -> 22af4a75cf06, First revision
In this case I updated migration f34e92e9dc54
to have down_revision='f673ac37b34a'
.