from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///example.db'
db = SQLAlchemy(app)
migrate = Migrate(app, db)
- Import necessary modules (
Flask
, SQLAlchemy
, Migrate
) from Flask and related extensions. - Create a Flask application instance.
- Set the database URI for SQLAlchemy to use (in this case, SQLite is used with a file named
example.db
). - Initialize the SQLAlchemy object (
db
) by passing the Flask application instance. - Create a migration engine (
migrate
) by passing the Flask application instance and SQLAlchemy object (db
) to the Migrate
class.