1.1 KiB
1.1 KiB
Database Migrations with Aerich
Initial Setup (Run Once)
- Install dependencies:
uv pip install -e .
- Initialize Aerich:
aerich init-db
This will:
- Create a
migrations/directory - Generate the initial migration based on your models
- Create all tables in the database
When You Add/Change Models
- Generate a new migration:
aerich migrate --name "describe_your_changes"
Example:
aerich migrate --name "add_user_profile_model"
- Apply the migration:
aerich upgrade
Common Commands
aerich init-db- Initialize database (first time only)aerich migrate --name "description"- Generate new migrationaerich upgrade- Apply pending migrationsaerich downgrade- Rollback last migrationaerich history- Show migration historyaerich heads- Show current migration heads
Docker Setup
In Docker, migrations run automatically on container startup via the startup script.
Notes
- Migration files are stored in
migrations/models/ - Always commit migration files to version control
- Don't modify migration files manually after they're created