flask-migrate

作用:做数据库迁移
依赖:
flask-script 
flask-sqlalchemy

使用

项目结构

manage.py(其它文件内容与flask-sqlalchemy中一样)

from s8day130_pro import create_app,db
from flask_script import Manager
from flask_migrate import Migrate,MigrateCommand


app = create_app()
manager = Manager(app)



Migrate(app, db)
"""
# 数据库迁移命名
    python manage.py db init
    python manage.py db migrate # makemigrations
    python manage.py db upgrade # migrate
"""
manager.add_command('db', MigrateCommand)


if __name__ == '__main__':
    # app.run()
    manager.run()

首先执行python manage.py db init会生成如下文件

然后就可以利用python manage.py db migrate和python manage.py db upgrade命令进行数据迁移了

posted on 2018-05-04 19:35  Py行僧  阅读(138)  评论(0编辑  收藏  举报