安装
pip install flask-migrate
代码
exts.py
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
db=SQLAlchemy() # 创建数据库连接对象
migrate=Migrate() # 创建迁徙对象
app.py
from flask import Flask,session,g
from exts import db,migrate
app=Flask(__name__)
db.init_app(app)
migrate.init_app(app,db)
命令
python manage.py db init # 初始化迁徙文件
python manage.py db migrate # 将模型添加到迁移文件
python manage.py db upgrade # 迁移文件中的ORM模型到数据库
标签:插件,flask,app,py,db,migrate,import
From: https://www.cnblogs.com/unity-yancy/p/17218032.html