The init
command that you put in the Procfile
creates a brand new Alembic repository, which is something you only do once on your development machine. When you deploy to a new machine all you need to do is run the upgrade
command to get the database created and updated to the last revision.
Alembic and Flask-Migrate have a command called stamp
that can help you fix this problem. With stamp
you can tell Alembic to write the revision of your choice to the database, without touching the database itself.
For example, creating a database from scratch when there are a lot of migrations can take a long time if Alembic has to go through all the migrations one by one. Instead, you can create the database with db.create_all()
and then run:
$ ./manage.py db stamp HEAD
and with this the database is marked as updated.
Also, at some point I favored the idea of putting maintenance commands in the Procfile
, but these days I only put services there, so I would only leave the web
line there. To upgrade the database I think it is more predictable to run the command explicitly:
$ heroku run python manage.py db upgrade