Database migration tool for SQLAlchemy. Manages schema versioning via migration scripts. Current version: 1.18.4 (Mar 2026). Tightly coupled to SQLAlchemy — version mismatch causes silent failures. SQLAlchemy 1.3 dropped in Alembic 1.15. Python 3.8 dropped in Alembic 1.15. The #1 footgun: autogenerate generates empty migrations when target_metadata is not correctly set in env.py.
pip install alembicVerified import paths — ran on the pinned version, not inferred.
Alembic setup and first migration workflow.
In env.py: import your models then set target_metadata = Base.metadata
Run 'alembic upgrade head' first, then run --autogenerate.
Use SQLAlchemy >= 1.4 and Python >= 3.9 with Alembic 1.15+
Always run 'alembic check' and manually review generated migration files before applying.
Run 'alembic merge heads -m merge' to create a merge migration. Then 'alembic upgrade head'.
Import all model files in env.py before target_metadata = Base.metadata.
In env.py: config.set_main_option('sqlalchemy.url', os.environ['DATABASE_URL'])Always use a virtual environment (e.g., `python -m venv .venv`) to install Python packages to avoid permission issues and system package manager conflicts. Avoid running pip commands with `sudo` unless absolutely necessary for system-wide tools, which is generally not recommended for application dependencies.
It is recommended to use a virtual environment or run pip as a non-root user. If running as root is intentional, use the `--root-user-action` option to suppress this warning.