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.
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
- Run
alembic upgrade headagainst the CI database first. - Then run autogenerate or the up-to-date check.
- Ensure migrations are committed so head matches what CI applies.
alembic upgrade head
alembic checkHow 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.