Alembic failed target database is not up to date means your database revision is behind the latest migration head and needs to be upgraded or stamped.
When the message Alembic failed target database is not up to date appears in your console, it interrupts work right away.
The good news: this specific alembic error has clear causes and predictable fixes, and once you understand how alembic tracks schema versions, you can clear it fast and keep it from turning up again.
This guide walks through what the target database is not up to date message means, how alembic decides that your database is behind, and the exact commands that bring your schema and migration history back in line.
You will also see how this fits with tools such as Flask-Migrate and how to fold checks into daily work so the error rarely appears.
What The “Alembic Failed Target Database Is Not Up To Date” Error Means
Alembic is a schema migration tool that stores each change as a small script called a revision.
Each revision has an identifier, and alembic keeps a row in an alembic_version table inside the database to record which revision has been applied most recently.
When you ask alembic to auto-generate a new revision with a command such as alembic revision --autogenerate or through a wrapper such as flask db migrate, it expects one thing:
the revision stored in alembic_version must match the latest head revision under your migrations/versions (or alembic/versions) folder.
If that check fails, you see the log line Target database is not up to date and alembic stops.
In short, the alembic failed target database is not up to date message means alembic believes there are unapplied migration scripts, or that your migration history and the database record do not match.
Common Causes Of Alembic Failed Target Database Is Not Up To Date
Although the wording looks vague, the real reasons tend to fall into a small set of patterns.
Once you match your situation to one of these patterns, the right fix becomes clear.
| Cause | Typical Symptom | Usual Fix |
|---|---|---|
| Unapplied revisions | New files in versions/, database still on an older revision |
Run alembic upgrade head to apply them |
| Fresh database with models already applied | Tables exist, but alembic_version is missing or empty |
Use alembic stamp head to mark the current state |
| Deleted or renamed revision file | alembic_version points to an id that no longer exists in code |
Restore the file or reset migration history carefully |
| Flask-Migrate sequence issues | flask db migrate fails with the same message |
Use flask db stamp head then migrate and upgrade again |
| Branches from multiple developers | Two heads or confusing history under versions/ |
Merge heads and apply the new merge revision on every database |
The exact wording “alembic failed target database is not up to date” can appear during autogenerate, during a custom alembic check run, or inside tools that wrap alembic.
In each case, the root cause still comes down to the database revision lagging behind the code revision, or to a mismatch between those two views of history.
Quick Checks Before You Try Any Fix
Before you change anything, it helps to see where alembic thinks your database stands right now and which revision it expects.
A short round of checks can prevent risky guesses on a live system.
Check The Current Database Revision
Run this command inside the same project folder that holds your alembic.ini and migration scripts:
alembic current
Alembic prints one or more revision ids, each with a flag that states whether the revision is the current head on that branch.
If nothing appears, the database might be missing the alembic_version table, or the command may not be using the same configuration that writes migrations.
Check The Head Revisions In Code
Next, ask alembic which revision or revisions count as heads in your code:
alembic heads
You may see a single id, or more than one if you have branches.
When alembic current and alembic heads show different ids for the same branch, the database is behind and the target database is not up to date message makes sense.
Confirm The Connection Target
Sometimes the alembic script connects to a different database than the one you expect.
Check the URL in alembic.ini or in the configuration that creates your engine and make sure it matches the database you intend to update.
Step-By-Step Fixes For A Stale Target Database
Once you know which revision the database holds and which heads exist in code, you can pick a safe path to clear the alembic failed target database is not up to date error.
Apply All Outstanding Revisions
This is the most common and least risky fix, especially when the database is behind because recent revisions were added but never applied.
- Back up the database — Take a snapshot using your database tools so you can roll back if a migration behaves in a way you did not expect.
- Apply migrations to head — Run
alembic upgrade headso every revision underversions/is applied in order.
When this finishes cleanly, the current revision and head revision line up again. - Re-run autogenerate — Now run
alembic revision --autogenerate -m "message"or your framework command.
With the target database at head, the earlier error should no longer appear.
Stamp A Pre-Existing Schema To Head
In some projects the database schema existed before alembic was introduced, or before a new service started to use it.
In that case, tables already match the latest models, but the alembic_version table is empty or missing, so alembic assumes the schema is at a base state.
- Verify schema matches models — Compare the live tables with the current models by hand or with a diff tool so you have confidence that the schema already represents the latest revision.
- Stamp the database — Run
alembic stamp head.
This writes the current head revision id intoalembic_versionwithout running any migration scripts. - Run autogenerate again — After stamping, try
alembic revision --autogenerateor your wrapper command.
Alembic now treats the target database as fully up to date.
Repair Or Reset Broken Revision History
If a revision file was deleted, renamed, or moved, the revision id stored in alembic_version may not exist in the code base anymore.
In that case, the target database is not up to date error often appears alongside messages about a missing revision id.
- Restore missing revision files — If the project used version control, bring back any removed files in the
versions/folder so alembic can load them again. - Align history on all databases — Make sure each database that uses this migration stream has the same set of revisions, especially when microservices share the same schema.
- As a last resort, rebuild migrations — In a development database, you can drop and recreate the schema, delete the existing
versions/scripts, and run throughalembic init,alembic revision --autogenerate, andalembic upgrade headagain.
Take extra care not to apply such a reset directly on production data.
Handle Multiple Heads And Branches
When teammates add different revisions on separate branches and merge them later, alembic might end up with more than one head revision.
If a database is missing one of those branches, you may see the target database error during autogenerate.
- List all heads — Run
alembic headsand check how many revisions appear at the top of the tree. - Generate a merge revision — Use
alembic mergeto generate a revision that brings branches together.-m "merge heads" - Upgrade every database through the merge — Run
alembic upgrade headon each database so they all share the same merged history before you call autogenerate again.
Working With Flask-Migrate And Other Wrappers
Many Flask projects use Flask-Migrate on top of alembic.
In those projects the same condition triggers the message: the database is behind the latest revision, or the revision table does not match what Flask-Migrate expects.
A common local repair sequence for a project that already has the right schema, but a missing or wrong revision record, looks like this:
- Stamp the database to head — Run
flask db stamp headso Flask-Migrate marks the current schema as matching the latest revision. - Regenerate a migration script — Run
flask db migrate -m "sync models"to rebuild the latest script that represents your models. - Apply the migration — Run
flask db upgradeto bring the alembic record and schema forward together.
That pattern mirrors the raw alembic commands: stamp to mark the current state, then migrate and upgrade to move forward in a clean way.
If you still see the same error afterward, repeat the quick checks for current and head revisions to confirm Flask-Migrate is using the same configuration as your direct alembic runs.
Preventing “Target Database Is Not Up To Date” In Daily Work
Clearing the message once is useful, but the real win comes when you rarely face it again.
A few lightweight habits around migration scripts and database use keep alembic aligned with your schema.
Apply Migrations As Part Of Every Deployment
- Run upgrades in automation — Add
alembic upgrade headorflask db upgradeto your deployment process so production never falls behind your code. - Keep a record of applied versions — Track schema changes in release notes so you can link any alembic error back to a specific change quickly.
Use Checks In Continuous Integration
- Verify migrations in CI — Run a pipeline step that builds a fresh test database, applies all migrations, and runs
alembic checkor an autogenerate dry run so missing migrations or mismatches show up before code merges. - Fail builds on schema drift — If autogenerate produces changes, have the pipeline fail with a clear message that the pull request needs a migration script.
Coordinate Migration Changes Across Teams
- Agree on naming and ordering — Use clear revision messages and, when possible, one central branch for database changes to reduce the number of heads that need later merges.
- Share reset procedures — Document the safe way to stamp, migrate, and upgrade local databases so new teammates do not end up with history that triggers target database errors.
Once you understand that alembic failed target database is not up to date simply points to a mismatch between migration history and the live schema, the error stops feeling mysterious.
With routine checks, careful use of upgrade and stamp, and a shared approach to migrations, you can keep every database in step with the code that depends on it.
