How can I fix alembic "The requested revision overlaps with other requested versions"?

I am working on a team using alembic to manage db migrations. I recently removed the wizard and tried to run alembic upgrade heads . I received the following message:

 INFO [alembic.runtime.migration] Context impl PostgresqlImpl. INFO [alembic.runtime.migration] Will assume transactional DDL. ERROR [alembic.util.messaging] Requested revision a04c53fd8c74 overlaps with other requested revisions 453d88f67d34 FAILED: Requested revision a04c53fd8c74 overlaps with other requested revisions 453d88f67d34 

I got the same message when I tried to run alembic downgrade -1 . Running alembic history prints this;

 453d88f67d34 -> a04c53fd8c74 (label_1, label_2) (head), Create such and such tables. 2f15c778e709, 9NZSZX -> 453d88f67d34 (label_1, label_2) (mergepoint), empty message b1861bb8b23f, b8aa3acdf260 -> 2f15c778e709 (label_1, label_2) (mergepoint), Merge heads b18 and b8a (...many more old revisions) 

which looks like a beautiful story to me. alembic heads reports a04c53fd8c74 (label_1, label_2) (head) .

The only thing that seems strange to me is that my version of abmbic db has two meanings:

 my_postgres=# SELECT * FROM alembic_version; version_num -------------- a04c53fd8c74 453d88f67d34 (2 rows) 

The only link I can find in googling exception is the source code , which I would not read.

How could such a situation be? How to fix it? What does "overlap" mean?

+12
source share
3 answers

I “fixed” it by deleting the older version number in the database;

 my_postgres=# DELETE FROM alembic_version WHERE version_num = '453d88f67d34'; DELETE 1 my_postgres=# SELECT * FROM alembic_version; version_num -------------- a04c53fd8c74 (1 row) 

Now I can run updates and downgrade. My story and heads look the same. But I still don't know why this happened, or is there some kind of db state that is subtly confused, so if someone has a better answer, send it!

+15
source

For those who found this, this happened to me because I tried to restore my database to an older version without dropping it first. I believe that in your alembic_version table alembic_version should be only one row with version_num any version your database should be on.

So, when I restored my database and did not abandon it first, instead of replacing the current version number, she added a new row. To fix this, I had to remove the wrong version from my alembic table (regardless of the version number of the database that I should have dropped first) ... just to give a little more context to Altair's answers.

+2
source
  1. The alembic_version table should only have one row for consistency.
  2. If you are restoring database data from a different version, the restore operation will ADD another row.
  3. After restoring the data, delete the row that was added from the restore operation.

This one worked for me:

 delete from alembic_version where version_num='e69ad4aec63b'; 
0
source

Source: https://habr.com/ru/post/1015227/


All Articles