Skip to content

Instantly share code, notes, and snippets.

@thinkjrs
Created June 13, 2022 19:37
Show Gist options
  • Select an option

  • Save thinkjrs/8644897fe0fd3a82cc92df51371c153d to your computer and use it in GitHub Desktop.

Select an option

Save thinkjrs/8644897fe0fd3a82cc92df51371c153d to your computer and use it in GitHub Desktop.
Flask-Migrate: Add multiple database setup to existing single database setup

Today we ran into an issue adding a multi-database setup to prior single-db setup. Here's how we fixed it and reference links.

What to do

From the maintainer of Flask-Migrate, Miguel Grinberg:

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.

References

miguelgrinberg/Flask-Migrate#179 (comment)

miguelgrinberg/Flask-Migrate#181 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment