Database migration command

Database Migration

  • In the development process, the need to modify the database model, but also to update the database after the modification. The most direct way is to delete the old table, but it will lose data.
  • A better solution is to use a database migration framework that can track changes in the database schema, and then apply the changes to the database.
  • Flask-Migrate extension may be used in the Flask to data migration. Flask-Script and integrated in order to complete all operations.
  • To derive database migration command, Flask-Migrate MigrateCommand provides a class, it can be attached to the object manager of the flask-script.

Specific migration command

python xxx.py db init 初始化迁移文件
python xxx.py db migrate -m"版本注释" 生成迁移版本
python xxx.py db upgrade 版本号 执行迁移

Python xxx.py db history 查看历史

python xxx.py db downgrade 版本号 (容易出现问题)


 

Guess you like

Origin blog.csdn.net/qwertyuiopasdfgg/article/details/93325126