Flask-migrate: configuring the version_table name

Created on 16 Sep 2015  Â·  5Comments  Â·  Source: miguelgrinberg/Flask-Migrate

From the alembic documentation, it appears that I should be able to change the name of the version_table from "alembic_version" to a name of my own choosing with something like:

config.set_main_option('version_table', 'my_alembic_version')

So, I added this to my "db init" generated migrations/env.py file just below the

config.set_main_option('sqlalchemy.url', current_app.config.get('SQLALCHEMY_DATABASE_URI'))

line. However, while I am getting the correct 'sqlalchemy.url' when I run the "db migrate" command, the version_table is still getting the default name. Am I missing something?

Please excuse me if there is a better forum for raising this question.

auto-closed question

Most helpful comment

Another solution that also helped, is to pass it as an additional keyword argument to either:

  • The Migrate constructor, e.g. Migrate(app, deb, version_table='versions')
  • The init_app() call, e.g. migrate.init_app(app, db, version_table='versions')

All 5 comments

I've never done this myself, but I believe the version_table option needs to be given to context.configure() call, not as a regular config file option. Did you try that?

Thanks! Adding the version_table=’my_alembic_version’ argument to the context.configure commands in the env.py command did the trick. Yes!

Just as an FYI, the reason I need this to maintain multiple separate groups of object tables in the same database instance. Being able to set different version_table names keeps the separate alembic migration directories from all trying to use the same alembic_version table and stomping on each other. (Sort of the opposite of the multidb situation, where you have one migration directory dealing with multiple database instances.) Of course, it also requires implementing an include_object method and passing it to context.configure as well. That restricts the tables each migration directory worries about, so it keeps alembic from generating commands to drop tables that are not part of its purview.

Thanks again,
Malcolm

From: Miguel Grinberg [mailto:[email protected]]
Sent: Wednesday, September 16, 2015 1:53 AM
To: miguelgrinberg/Flask-Migrate
Cc: Davis, Malcolm
Subject: Re: [Flask-Migrate] configuring the version_table name (#83)

I've never done this myself, but I believe the version_table option needs to be given to context.configure() call, not as a regular config file option. Did you try that?

—
Reply to this email directly or view it on GitHubhttps://github.com/miguelgrinberg/Flask-Migrate/issues/83#issuecomment-140634643.


This message (including any attachments) may contain confidential, proprietary, privileged and/or private information. The information is intended to be for the use of the individual or entity designated above. If you are not the intended recipient of this message, please notify the sender immediately, and delete the message and any attachments. Any disclosure, reproduction, distribution or other use of this message or any attachments by an individual or entity other than the intended recipient is prohibited.

wow i have been trying to figure this out for a VERY long time. thank you.

Another solution that also helped, is to pass it as an additional keyword argument to either:

  • The Migrate constructor, e.g. Migrate(app, deb, version_table='versions')
  • The init_app() call, e.g. migrate.init_app(app, db, version_table='versions')

This issue will be automatically closed due to being inactive for more than six months. Seeing that I haven't responded to your last comment, it is quite possible that I have dropped the ball on this issue and I apologize about that. If that is the case, do not take the closing of the issue personally as it is an automated process doing it, just reopen it and I'll get back to you.

Was this page helpful?
0 / 5 - 0 ratings