July 2019
Beginner to intermediate
302 pages
9h 38m
English
To enable migrations, we need to modify our app definition a bit. Let's understand how such a config appears if we modify the same for our catalog application:
The following lines of code show how my_app/__init__.py appears:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate, MigrateCommand
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
db = SQLAlchemy(app)
migrate = Migrate(app, db)
import my_app.catalog.views
db.create_all()
If we pass --help to the flask command while running it as a script, the Terminal will show all the available options, as shown in the following screenshot:
To initialize migrations, run the init command:
$ flask ...