Skip to main content

How to add Flask-Migrate to our Flask app

Adding Flask-Migrate to our app is simple, just install it and add a couple lines to

To install:

pip install flask-migrate

This will also install Alembic, since it is a dependency.

Then we need to add 2 lines to (highlighted):

from flask_smorest import Api
from flask_migrate import Migrate

import models

app.config["PROPAGATE_EXCEPTIONS"] = True
migrate = Migrate(app, db)
api = Api(app)

with app.app_context():

Since we will be using Flask-Migrate to create our database, we no longer need to tell Flask-SQLAlchemy to do it when we create the app.

Delete these two lines:

with app.app_context():