Alembic "Target database is not up to date" in CI
Alembic autogenerate compares your models against the current database, which it requires to be at head first. If the database has unapplied revisions, Alembic refuses with "Target database is not up to date".
What this error means
alembic revision --autogenerate (or alembic check) fails with "Target database is not up to date." because the database is behind the latest revision.
FAILED: Target database is not up to date.Common causes
Pending revisions were not applied
The database is behind head; autogenerate needs it fully upgraded so it diffs against the latest schema state.
A fresh CI database with no migrations applied
The job created an empty database but never ran alembic upgrade head, so the version table is behind the revisions on disk.
How to fix it
Upgrade to head before autogenerate or check
Apply all pending revisions so the database is at head, then run autogenerate or check.
alembic upgrade head
alembic revision --autogenerate -m "new change"Use alembic check as a drift gate
- Run
alembic upgrade headagainst the CI database. - Run
alembic checkto confirm models and migrations agree. - Fail CI if
checkreports new operations to generate.
alembic upgrade head
alembic checkHow to prevent it
- Always
alembic upgrade headbefore autogenerate or check. - Run migrations against a clean database that you then upgrade.
- Add
alembic checkto CI to catch model/migration drift.