[Python] Alembic: "Can't locate revision" error after deleting migration file and recreating...

Discussão em 'Python' iniciado por Stack, Julho 1, 2025.

  1. Stack

    Stack Membro Participativo

    I accidentally deleted the migration file before running alembic upgrade head. Then I recreated the migration using the same command again. This time, Alembic generated a new revision UUID.

    When I try to run: alembic upgrade head

    I get this error:

    INFO [alembic.runtime.migration] Context impl SQLiteImpl.
    INFO [alembic.runtime.migration] Will assume non-transactional DDL.
    ERROR [alembic.util.messaging] Can't locate revision identified by 'e5ae7c79da87'
    FAILED: Can't locate revision identified by 'e5ae7c79da87'


    The original migration (now deleted) had the revision ID e5ae7c79da87. The database partially updated before (two tables were created). Even after deleting the database file, the error persists when I try to run migrations again.

    Deleting and recreating the SQLite .db file. Running alembic stamp head or alembic stamp base. Regenerating a new migration using --autogenerate.

    How can I cleanly reset Alembic so it stops looking for the deleted revision e5ae7c79da87 and applies my new migration correctly?

    Is there a recommended way to handle deleted/missing revision files when a partial migration was applied?

    Continue reading...

Compartilhe esta Página