Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I delete a similar alembic version?

When I am trying to do

alembic upgrade head

I am getting this error:

ERROR [alembic.util.messaging] Online migration expected to match one row when updating '3aae6532b560' to 'a1d8dae7cc' in 'alembic_version'; 2 found
FAILED: Online migration expected to match one row when updating '3aae6532b560'
to 'a1d8dae7cc' in 'alembic_version'; 2 found

alembic current

gives two similar versions of alembic like:

3aae6532b560
3aae6532b560

How do I delete one of the similar versions of alembic, i.e a copied version?

alembic history doesn't show any messed up output.

Thanks!

like image 485
trishnag Avatar asked Jul 07 '16 14:07

trishnag


People also ask

What method is called to undo an alembic database revision?

If you want to run to downgrade() of a version, you will need to run alembic downgrade the-version-before-it , which mean it will revert to the version after the version that you want to downgrade. Which is the version before the version that we want to revert.

How do I know what version of alembic I have?

run pip freeze | grep "alembic" .

What is alembic revision?

Alembic is the migration tool we use with SQLAlchemy. Alembic provides us with a simple way to create and drop tables, and add, remove, and alter columns. Fork and clone this repository and we'll walk through writing Alembic migrations together. To install Alembic, run pip install alembic in your terminal.

How do you change heads in alembic?

Show activity on this post. Delete (or move to another folder) the specific migration file (in migrations/versions folder). The head will automatically revert to the most recent remaining migration. Using stamp will set the db version value to the specified revision; not alter the head revision number.


1 Answers

Alembic version is stored within your database in alembic_version table. I see that you have two self same rows inside the table.

You can do something like this:

DELETE FROM alembic_version WHERE version_num='3aae6532b560';
INSERT INTO alembic_version VALUES ('3aae6532b560');

Above query could be done in one query by limiting number of deleted rows, but limiting within DELETE query is different between different databases engines.

like image 100
Karol Pawłowski Avatar answered Sep 28 '22 17:09

Karol Pawłowski