Technology moves fast! ⚡ Don't get left behind.🚶 Subscribe to our mailing list to keep up with latest and greatest in open source projects! 🏆


Subscribe to our mailing list

Flask-Migrate

SQLAlchemy database migrations for Flask applications using Alembic

Subscribe to updates I use Flask-Migrate


Statistics on Flask-Migrate

Number of watchers on Github 881
Number of open issues 48
Average time to close an issue 20 days
Main language Python
Average time to merge a PR 6 days
Open pull requests 6+
Closed pull requests 15+
Last commit over 1 year ago
Repo Created almost 6 years ago
Repo Last Updated over 1 year ago
Size 126 KB
Organization / Authormiguelgrinberg
Contributors16
Page Updated
Do you use Flask-Migrate? Leave a review!
View open issues (48)
View Flask-Migrate activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating Flask-Migrate for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

Flask-Migrate

Build Status

Flask-Migrate is an extension that handles SQLAlchemy database migrations for Flask applications using Alembic. The database operations are provided as command line arguments for Flask-Script.

Installation

Install Flask-Migrate with pip:

pip install Flask-Migrate

Example

This is an example application that handles database migrations through Flask-Migrate:

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db'

db = SQLAlchemy(app)
migrate = Migrate(app, db)

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(128))

With the above application you can create the database or enable migrations if the database already exists with the following command:

$ flask db init

Note that the FLASK_APP environment variable must be set according to the Flask documentation for this command to work. This will add a migrations folder to your application. The contents of this folder need to be added to version control along with your other source files.

You can then generate an initial migration:

$ flask db migrate

The migration script needs to be reviewed and edited, as Alembic currently does not detect every change you make to your models. In particular, Alembic is currently unable to detect indexes. Once finalized, the migration script also needs to be added to version control.

Then you can apply the migration to the database:

$ flask db upgrade

Then each time the database models change repeat the migrate and upgrade commands.

To sync the database in another system just refresh the migrations folder from source control and run the upgrade command.

To see all the commands that are available run this command:

$ flask db --help

Resources

Flask-Migrate open issues Ask a question     (View All Issues)
  • over 2 years Need to upgrade multiple database in parallel, not serially
  • over 2 years Migration hangs in the middle.
  • almost 3 years migrate only tables in my model
  • almost 3 years upgrade and add value to a column
  • almost 3 years Migration cannot read database file inside a folder
  • almost 3 years Tests cannot be run on python3
  • about 3 years Detecting binds without --multidb flag
  • about 3 years If I only modify the column type, the migrate doesn't detect it.
  • about 3 years AttributeError: 'module' object has no attribute 'create_module_class_proxy'
  • about 3 years Can't work
  • over 3 years Datetime in filename migration
  • over 3 years AttributeError when calling context.get_x_argument without specifying -x
  • over 3 years Add to README Section on Why use Flask-Migrate vs just Alembic
  • over 3 years Alembic didn't detect column change: Error: no support for ALTER of constraints in SQLite dialect
  • over 3 years Question: How can I handle stored procedures with Flask-Migrate?
  • over 3 years application structure ??
  • over 3 years Cross database foreign key support
  • almost 4 years Not created table.
  • almost 4 years from alembic.revision import ResolutionError ImportError: No module named revision
  • almost 4 years configuring the version_table name
  • almost 4 years sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) Cannot add a NOT NULL column with default value NULL
  • almost 4 years How do I run migrations for testing?
  • about 4 years How do I add "import sqlalchemy_utils" automaitically to the migration file
  • about 4 years ALTER table - Flask-migrate and sqlite
  • over 4 years Can't detect models.py schema
Flask-Migrate open pull requests (View All Pulls)
  • Allow providing only db at instantiation
  • Update env.py
  • Flask 1.0 update
  • Add SQLAlchemy-Utils
  • allow -x argument for migrate command
  • be more careful with PYTHONPATH when invoking flask
Flask-Migrate questions on Stackoverflow (View All Questions)
  • How do you use Flask-Migrate commands with a multi-file setup?
  • Run app from Flask-Migrate manager
  • Flask migrate ignoring foreign key
  • How to autoimport module in flask-migrate migration
  • Flask-Migrate: Data migrations do not aplly after schema migrations together
  • Flask Migrate: Alembic converting choices into 255
  • Flask-migrate and changing column type
  • flask migrate seemed to delete all my database data
  • Flask-Migrate Error: 'ConfigParser.NoSectionError: No section: 'alembic''
  • How do I use flask Migrate and SQLAlchemy on my own database, and connect to a third party database that I do not wish to migrate?
  • Can't migrate or upgrade database with Flask-Migrate (Alembic)
  • flask-migrate can't import modules
  • Flask-Migrate "No section: 'alembic'" on "db migrate" command
  • Flask-Migrate won't update the tables
  • Why Flask-migrate cannot upgrade when drop column
  • using flask-migrate with flask-script, flask-socketio and application factory
  • Running flask-migrate on heroku produces error
  • using flask-migrate with flask-script and application factory
  • change database migrations from sqlalchemy-migrate to Flask-Migrate
  • flask-migrate wants to drop my indeces
  • Why is Flask-Migrate making me do a 2-steps migration?
  • Flask-Migrate not creating migrations
  • flask-migrate doesn't detect models
  • How do I use flask-migrate on pythonanywhere?
  • flask-migrate doesn't work When I add models with ForeignKey
  • using Flask-Migrate together with Flask-Security
  • Flask-migrate multiple models.py
  • Flask-migrate on openshift
  • Flask-Migrate, do not create tables if exists
  • Flask-Migrate: column addition / removal apparently undetected, tables recreated instead
Flask-Migrate list of languages used
Other projects in Python