Error upgrading database with Alembic12 November 2016
On my last project I started using Alembic as a migration tool for the database, which is a new thing for me.
Before that I used to simply keep a file with the modifications applied to the developement database between each release version and patch the test and production datbase accordingly. Some of the drawbacks to this method are a risk of manipulation error and it is very difficult to reverse the changes when they are applied.
Today while performing an upgrade on the production database running Postgresql with Alembic :
alembic upgrade head
I received the following error :
... ERROR [alembic.util.messaging] Online migration expected to match one row when updating '7b4f4b275d5b' to 'cca4e32787e4' in 'alembic_version'; 2 found ...
Each database that Alembic work with has an "alembic_version" table, with one column, which contains the id of the current version of the database.
In my database there was two rows in the table alembic_version both with the same value. As the table has no other column to differentiate the rows it is a little bit tricky to remove only one but this did the trick :
DELETE FROM alembic_version WHERE ctid IN (select ctid from alembic_version LIMIT 1);
I do not know why there was two entries in the table but removing one fixed the problem.