Cleaning Up Your Very First (Bad) Alembic Migration

As with many things, the first time you try something, it often doesn’t go well. And recently we’ve adopted using alembic for database migrations with a python-based project. Conceptually, alembic is a lot like git–each migration is a commit-like object that you can apply (upgrade) or remove (downgrade). And an autogenerated hash is assigned to each migration with a pointer back to the has for the previous commit.

Except when it is the first one.

For that first migration, it points back to an empty string. So after trying various pythonic options (<nothing>, an empty string, None, -1), all of which failed, I read a reference in the alembic docs where it called the initial state (or parent) “base”.

Alas that works!

alembic downgrade base

Mess averted, problem solved, & we’re back to the beginning again. Now let’s give that database migration another try…

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.