Created
May 17, 2018 00:59
-
-
Save kosmosr/f9977078016794ddb1a9e9dbab74f32a to your computer and use it in GitHub Desktop.
flask 数据库迁移框架
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
""" | |
@author: zmh | |
@time: 2018/5/17 8:46 | |
数据库迁移脚本 | |
""" | |
from flask_migrate import Migrate, MigrateCommand | |
from flask_script import Manager | |
from flask_app.app import app, db | |
# 导入需要迁移的数据库模型 | |
from model.article import Article | |
from model.category import Category | |
from model.user import User | |
# 让python支持命令行工作 | |
manager = Manager(app) | |
# 使用migrate绑定app和db | |
migrate = Migrate(app, db) | |
# 添加迁移脚本的命令到manager中 | |
manager.add_command('db', MigrateCommand) | |
if __name__ == '__main__': | |
manager.run() | |
# 初始化 python manage.py db init | |
# 创建迁移脚本 python manage.py db migrate | |
# 更新数据库 python manage.py db upgrade |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment