51777190
This method can:
Https://www.cnblogs.com/caicairui/p/7821586.html
ImportOS fromAppImportCreate_app, DB fromFlask_scriptImportManager, Shell fromFlask_migrateImportMigrate, Migratecommand#app = Create_app (os.getenv (' flask_config ') or ' default ')App =Create_app () Manager=Manager (APP) Migrate=Migrate (app, db) Manager.add_command ('DB', Migratecommand)if __name__=='__main__': Manager.run ()
First time use:
- Initialize: (venv) python manage.py db init This command creates the Migrations folder under the project, where all migration scripts are stored.
- Create first version: (venv) $ python manage.py db migrate-m "Initial migration" check Migrations\versions, a new version is created. PY, check the form and field inside
- Running the upgrade (venv) $ python manage.py DB upgradewill update the database files used by the project to new tables, fields, while preserving the data
Suffix Update:
- Update a table's fields (models.py)
- Run again db migrate-m, equivalent to commit update to/migrate directory
- DB upgrade-database is updated
Initialization
(venv) $ Python manage.py db init
Create a migration script
(venv) $ Python manage.py db migrate
Update Database
(venv) $ python manage.py db upgrade
Flask's Migrate