创建迁移仓库:

1.安装工具:

pip install flask_migarte

2.代码:

#encoding:utf-8
from flask_sqlalchemy import SQLAlchemy
from flask_script import Manager,Shell
from flask_migrate import Migrate,MigrateCommand
from flask import Flask

app = Flask(__name__)
db = SQLAlchemy(app)
migrate = Migrate(app,db)
manager = Manager(app)
manager.add_command('db',MigrateCommand)

def make_shell_context():
    return dict(app=app,db=db)

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

3.执行:

python index.py db init

4.效果:

flask 入门 之 Python Shell (二)

flask 入门 之 Python Shell (二)

5.己经创建了迁移仓库,我们需要创建一个迁移对象,把它放在仓库中,用来以后更新和恢复:

  迁移角本:

python index.py db migrate -m "initial migration"

6.更新数据库(应用迁移角本):

python index.py db upgrade

7.回退数据库(返回上一个迁移角本):

  python index.py db downgrade

 

相关文章:

  • 2022-12-23
  • 2021-07-20
  • 2022-12-23
  • 2021-11-13
  • 2022-12-23
  • 2021-08-09
  • 2021-08-13
  • 2021-08-24
猜你喜欢
  • 2021-10-05
  • 2021-09-28
  • 2021-06-06
  • 2022-01-05
  • 2021-12-29
  • 2021-06-23
  • 2022-01-19
相关资源
相似解决方案