Flask-Migrate / Migrations
Flask-Migrate is the extension that adds database migrations to Flask using Alembic. Migrations are versioned scripts that evolve your database schema (adding columns, tables, indexes) in step with your models.
Flask
Once an app is in production you cannot just call db.create_all() to change tables without losing data. Migrations record each schema change as a script so you can apply, review, and roll back changes safely across environments.
The typical workflow uses three CLI commands: `flask db init` to set up the migrations folder once, `flask db migrate -m "message"` to auto-generate a script from model changes, and `flask db upgrade` to apply it. `flask db downgrade` reverses the most recent one.
Auto-generated migrations are a starting point, not gospel — always read the generated script, because Alembic cannot detect every change (such as some column renames, which it sees as a drop plus an add).
Syntax
flask db migrate -m "add email"
flask db upgradeExamples
Python
from flask_migrate import Migrate
db = SQLAlchemy(app)
migrate = Migrate(app, db)
# then on the command line:
# flask db init
# flask db migrate -m "create users"
# flask db upgrade