Manage database migrations with the flask db CLI
mainFlask-Migrate provides database operations via the flask db command group. Follow this workflow to manage your schema:
- Initialize migrations: Run
flask db initto create themigrationsfolder. This is done once per project. - Generate a migration script: Run
flask db migrateto detect changes in your models and generate a migration script. Important: Review and edit the generated script manually, as Alembic may not detect all changes (e.g., it currently cannot detect indexes). - Apply migrations: Run
flask db upgradeto apply the migration scripts to the database.
To sync a database on another system, pull the migrations folder from version control and run flask db upgrade.