What this thread does
The problem
Your agent cannot generate or apply a migration. Distinguish unapplied revisions from missing files before changing anything. All commands below are proposed project repairs, not executions for this draft. Alembic commands that inspect or upgrade the database use the configured connection.
Versions and scope
| Tool | Official evidence | Boundary |
|---|---|---|
| Alembic | Command docs identify themselves as 1.20.1 as of November 2026 (checked 2026-11-15) | Documentation version; supplied reports establish no installed version |
| Flask-Migrate | Workflow separates migrate and upgrade | No release pin inferred |
| Drizzle | Issue #680 reports ORM 0.26.3 and Kit 0.18.1 | Historical journal-based setup, not a latest-version recommendation |
| Drizzle conversion | v1 upgrade guide uses the rc tag and removes the journal layout | Converted projects need compatible tooling, not recreated legacy metadata |
Choose the repair
| Evidence | Action |
|---|---|
| Alembic resolves history but applied revision is behind | Review and apply pending scripts before autogeneration |
| Alembic cannot resolve a recorded revision | Restore matching history or correct the environment |
| Journal-based Drizzle cannot read its journal | Check generation, paths and deployment artifacts |
| Drizzle history has the new layout | Follow the upgrade guide with compatible tooling |
Target database is not up to date.
The exact message is Target database is not up to date. The official autogenerate source checks revisions against script heads. Being behind prevents autogeneration (checked 2026-10-20).
alembic current
alembic heads
alembic history --verbose
For one intended head, review pending scripts and confirm the target, then apply them before generating another change.
alembic upgrade head
alembic revision --autogenerate -m "describe_change"
Flask-Migrate equivalents are flask db current, flask db heads, flask db upgrade, then flask db migrate -m "describe_change". Review the generated script. Sources are the Alembic tutorial and Flask-Migrate workflow, checked 2026-10-20.
Do not stamp just to silence the error. The command reference says stamping updates revision metadata without running migrations (checked 2026-10-20). A baseline needs proof that the schema already matches. Multiple heads need branch-aware review rather than a blind single-head upgrade.
Can't locate revision identified by '31b8ab83c7d'
That exact message and ID appear in the supplied report; there is no internal space. The official resolver raises it for an unresolved requested revision (checked 2026-10-20).
Missing scripts are one explanation; a wrong checkout, script directory or environment can select unrelated history. Substitute your actual migration directory below.
alembic history --verbose
alembic show 31b8ab83c7d
rg -n '31b8ab83c7d|down_revision' migrations
git log --all -- migrations
Restore the original script and missing ancestors from a verified release. Replace placeholders after reviewing that release's history.
git restore --source=<known-good-ref> -- <missing-migration-path>
alembic history --verbose
alembic current
Then apply pending scripts using the earlier workflow. For environments sharing a database, maintainer zzzeek explains separate version-table configuration in Alembic #722, checked 2026-10-20. Correct the environment/table mapping only after establishing which history owns the schema.
Do not drop the version table, rewrite IDs, invent an empty replacement revision or delete the migration directory. Unrecoverable history needs a reviewed baseline plan, not a universal reset command.
Can't find meta/_journal.json file
The exact message is Can't find meta/_journal.json file. The official reader checks <migrationsFolder>/meta/_journal.json before reading referenced SQL files (checked 2026-10-20).
Compare config out, runtime migrationsFolder, working directory and deployed artifact. For a folder named drizzle, inspect locally with these commands.
pnpm list drizzle-orm drizzle-kit
pnpm exec drizzle-kit --help
pwd
ls drizzle/meta/_journal.json
git ls-files drizzle
If no migration has ever been generated, use the installed Kit's documented generation command. The current generate reference documents this form (checked 2026-10-20).
pnpm exec drizzle-kit generate --config=drizzle.config.ts
Historical Kit used forms such as generate:pg; check installed help before using modern syntax. For established history restore committed artifacts instead of generating a replacement initial migration. Package the journal and every referenced SQL file into the migration job, align paths, then use the project's existing migration job. The config reference defines the output directory (checked 2026-10-20).
Do not hand-write an empty journal, delete metadata or substitute schema push. Moving migrations out of request initialization does not create missing files. Converted layouts need compatible tooling, not a fabricated legacy journal.
What the community establishes
- In Drizzle #680, Aaditya-23 reports deployment failure. ESchouten suggests a separate migration step, confirmed by the author. lightbluepoppy separately reports skipped generation. These are distinct cases (checked 2026-10-20).
- vitaly-krugl's Alembic #722 has zzzeek's maintainer answer on version-table ownership, showing that missing files are not the only cause (checked 2026-10-20).
- The up-to-date question reports an autogeneration error. davidism distinguishes applying migrations from deliberate stamping. This is a historical report, not current incidence (checked 2026-11-15).
A prompt to give your agent
Read the linked official command docs, resolver source and Drizzle reader before proposing a repair; do not guess. Report exact errors and installed versions. Inspect tracked migrations, paths and deployed artifacts without displaying credentials. Separate unapplied history from missing history. Propose a minimal repair and verification commands. Do not stamp, reset, push, delete metadata or apply changes to a real database without a reviewed plan.
Limits
No migration, database, deployment or reproduction was run. Unverified supplied string Can't locate revision identified by '31 b8ab83c7d' is dropped; the report verifies only the unspaced form. No other requested string was dropped. Alembic report versions remain unknown. Community evidence is case reports; current recurrence and supplied Drizzle reaction totals were not established. The new Drizzle layout was not tested.
Started from a post by @Aaditya-23, packaged by the editor. Original post