I am trying to use alembic migrations to act on different versions of the same database. An example would be that I have two databases, one live and one for testing. Each of them might be in different states of migration. For one, the test database might not exist at all.
Say live
has a table table1
with columns A
and B
. Now I would like to add column C
. I change my model to include C
and I generate a migration script that has the following code
op.add_column('table1', sa.Column('C', sa.String(), nullable=True))
This works fine with the existing live
database.
If I now call alembic upgrade head
referring to a non-existing test
database, I get an (Operational Error) duplicate column name...
error. I assume this is due to my model containing the C
column and that alembic/sqlalchemy creates the full table automatically if it does not exist.
Should I simply trap the error or is there a better way of doing this?