Database Migrations with Alembic
Evolve your SQLAlchemy schema safely over time using Alembic: initialize migrations, autogenerate revisions, and apply or roll back changes in a FastAPI project.
Why Migrations
Your database schema changes as your app grows: new columns, tables, and indexes. Migrations are versioned, repeatable scripts that evolve the schema without losing data. Alembic is the standard tool for SQLAlchemy.
create_all Is Not Enough
Base.metadata.create_all() creates missing tables but never alters existing ones. It cannot add a column to a populated table or track history. Production needs real migrations.
All lessons in this course
- SQLAlchemy ORM Fundamentals
- Connecting FastAPI to PostgreSQL
- CRUD Operations with SQLAlchemy
- Database Migrations with Alembic