Perform migrations
This guide explains how to manage database migrations in your project. Migrations are essential for evolving your database schema over time while preserving existing data.
Creating a migration⚓︎
To create a new migration after modifying your models, use the following command:
This command will generate a new migration script in the migrations/versions directory. Review the generated script to ensure it accurately reflects the changes you made to your models.
Applying migrations⚓︎
Once you have created a migration, you need to apply it to your database. Use the following command to upgrade your database schema to the latest revision:
This command will apply all pending migrations to your database.
Downgrading migrations⚓︎
If you need to revert to a previous migration, you can use the downgrade command. Specify the target revision you want to downgrade to:
Replace <target_revision> with the specific revision identifier you want to revert to. You can also use relative revisions numbers (e.g., -1 to go back one revision, -5 to go back five revisions, etc.).