Flask-migrate: add additional database after db init has been run

Created on 4 Jan 2018  路  1Comment  路  Source: miguelgrinberg/Flask-Migrate

I have run flask db init with just one database (very long ago). Now I want to add a second database to my application.
I have already created the binds. But running flask db migrate is just ignoring my __bind_key__ set at the newly created model class.
I tried to run flask db init --multdib but this gives me alembic.util.exc.CommandError: Directory migrations already exists.

How can I tell flask-migrate I have two databases now?

question

Most helpful comment

I was able to convert a single-db repository to multi-db with the following procedure:

  • backup everything just in case!
  • rename your migrations folder to something else (i.e. migrations-old)
  • run flask db init --multidb
  • copy the contents of migrations-old/versions/* to migrations/versions.
  • run flask db stamp head (this marks the additional databases as being updated)
  • delete migrations-old

At this point you should have a repository that can track changes in all your databases.

>All comments

I was able to convert a single-db repository to multi-db with the following procedure:

  • backup everything just in case!
  • rename your migrations folder to something else (i.e. migrations-old)
  • run flask db init --multidb
  • copy the contents of migrations-old/versions/* to migrations/versions.
  • run flask db stamp head (this marks the additional databases as being updated)
  • delete migrations-old

At this point you should have a repository that can track changes in all your databases.

Was this page helpful?
0 / 5 - 0 ratings