Skip to main content

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 under the flask db command.

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

Release files for Flask-Migrate 4.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Flask-Migrate 4.1.0
File Size Uploaded
flask_migrate-4.1.0.tar.gz 22.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Flask-Migrate 4.1.0
File Interpreter ABI Platform
Flask_Migrate-4.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 43.2 kB

Release files / flask_migrate-4.1.0.tar.gz

Download URL flask_migrate-4.1.0.tar.gz
Size 22.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1a336b06eb2c3ace005f5f2ded8641d534c18798d64061f6ff11f79e1434126d
BLAKE2b-256 checksum
How to use checksums
5a8e47c7b3c93855ceffc2eabfa271782332942443321a07de193e4198f920cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.13.0

Release files / Flask_Migrate-4.1.0-py3-none-any.whl

Download URL Flask_Migrate-4.1.0-py3-none-any.whl
Size 21.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
24d8051af161782e0743af1b04a152d007bad9772b2bca67b7ec1e8ceeb3910d
BLAKE2b-256 checksum
How to use checksums
d2c43f329b23d769fe7628a5fc57ad36956f1fb7132cf8837be6da762b197327
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.13.0

Release history Release notifications | RSS feed

This release

4.1.0 This release

2 release files

4.0.7

2 release files

4.0.6

2 release files

4.0.5

2 release files

4.0.4

2 release files

4.0.3

2 release files

4.0.2

2 release files

4.0.1

2 release files

4.0.0

2 release files

3.1.0

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.7.0

2 release files

2.6.0

2 release files

2.5.3

2 release files

2.5.2

2 release files

2.5.1

2 release files

2.5.0

2 release files

2.4.0

2 release files

2.3.1

2 release files

2.3.0

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.1

2 release files

2.1.0

1 release file

2.0.4

1 release file

2.0.3

1 release file

2.0.2

1 release file

2.0.1

1 release file

2.0.0

1 release file

1.8.1

1 release file

1.8.0

1 release file

1.7.0

1 release file

1.6.0

1 release file

1.5.1

1 release file

1.5.0

1 release file

1.4.0

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.0

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.0

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page