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
- 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.
Terminal
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.
Related guides
Alembic Autogenerate Produces Empty or Wrong Migration in CIFix Alembic "autogenerate" producing an empty migration or "Target database is not up to date" in CI - models…
Python "sqlalchemy.orm.exc.DetachedInstanceError" in CIFix "DetachedInstanceError: Instance is not bound to a Session" in CI - a SQLAlchemy object was accessed afte…
Python "sqlalchemy.exc.IntegrityError: UNIQUE constraint failed" in CIFix "sqlalchemy.exc.IntegrityError: UNIQUE constraint failed" in tests in CI - a row violated a unique constr…