Skip to content
Latchkey

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.

alembic output
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.

Terminal
alembic upgrade head
alembic revision --autogenerate -m "new change"

Use alembic check as a drift gate

  1. Run alembic upgrade head against the CI database.
  2. Run alembic check to confirm models and migrations agree.
  3. Fail CI if check reports new operations to generate.
Terminal
alembic upgrade head
alembic check

How to prevent it

  • Always alembic upgrade head before autogenerate or check.
  • Run migrations against a clean database that you then upgrade.
  • Add alembic check to CI to catch model/migration drift.

Frequently asked questions

What causes "Alembic "not up to date""?
The database is behind head; autogenerate needs it fully upgraded so it diffs against the latest schema state.
How do I fix Alembic "not up to date"?
Apply all pending revisions so the database is at head, then run autogenerate or check.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card