Skip to content
Latchkey

Python "alembic.util.exc.CommandError: Target database is not up to date" in CI

alembic.util.exc.CommandError: Target database is not up to date is raised when alembic detects unapplied migrations before an operation that requires the schema to be current, typically autogenerate.

What this error means

An alembic step fails with "alembic.util.exc.CommandError: Target database is not up to date." during revision --autogenerate or a check.

python
alembic.util.exc.CommandError: Target database is not up to date.

Common causes

The CI database was not migrated to head

A fresh CI database was created but alembic upgrade head did not run before the autogenerate/check.

A pending migration exists that was not applied

A newer revision is present in code but the database is still on an older revision.

How to fix it

Upgrade to head before the operation

  1. Run alembic upgrade head against the CI database first.
  2. Then run autogenerate or the up-to-date check.
  3. Ensure migrations are committed so head matches what CI applies.
Terminal
alembic upgrade head
alembic check

How to prevent it

  • Always upgrade the CI database to head before schema checks.
  • Add an alembic check step to catch missing migrations in PRs.
  • Keep migration files committed and ordered.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →