简体   繁体   中英

Will Flask-Migrate migrations work across different database engines?

I am writing a Flask application that uses Flask-SQLAlchemy and Flask-Migrate. Production has a PostgreSQL database, but for development, I was hoping to use SQLite instead of having to install full PostgreSQL on my development machine.

I set up Flask-Migrate as described in its docs . I can't help but notice, when I run flask db migrate on the dev box, these are the first two lines written to console:

INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.

My question: Does this mean that the generated migration script is only suitable for SQLite?

I would have expected not, since you're supposed to commit the script to version control (after you give it a manual inspection) and use it for migration in production. And the author of Flask-Migrate himself admits one of the benefits of SQLAlchemy is you can use a different database engine in development and production (see his blog post ). But then, why is it telling me about these assumptions? Is there a way to tell it not to assume a specific database engine?

The Context impl SQLiteImpl message that Alembic prints is actually a result of the database URL that is configured in your application. This URL is fed into Alembic, which allocates the proper driver for your chosen database. In your production environment you will see Context impl PostgresqlImpl instead.

Using different database in development and production is fine, but you have to be careful to make the contents of your migrations generic enough that work on both. You will not be able to use Postgres or SQLite specific features, obviously. I also recommend that add a staging server that is also based on Postgres where you can test your migrations before running them on production.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM