I have 2 migration scripts.
Script 1: Base
from models import EntityProperty
from contextlib import contextmanager
# revision identifiers, used by Alembic.
revision = 'ecbde8fa83e3'
down_revision = None
branch_labels = None
depends_on = None
from alembic import op # noqa
import sqlalchemy as sa # noqa
@contextmanager
def session_scope():
session = sa.orm.session.Session(bind=op.get_bind())
try:
yield session
session.commit()
except:
session.rollback()
raise
finally:
session.close()
def _upgrade(session):
properties = session.query(EntityProperty).filter(
~EntityProperty._ptype.in_(["AI", "AO", "AV"])
).all()
for _property in properties:
_property._cov_increment = None
def upgrade():
with session_scope() as session:
_upgrade(session)
def downgrade():
pass
Script 2:
revision = 'ab47480a7be7'
down_revision = u'ecbde8fa83e3'
branch_labels = None
depends_on = None
from alembic import op # noqa
import sqlalchemy as sa # noqa
def upgrade():
# add bacnet_enable to EP
with op.batch_alter_table(u'entityproperties', schema=None) as batch_op:
batch_op.execute("PRAGMA foreign_keys=OFF;")
batch_op.add_column(
sa.Column(
'bacnet_object', sa.Boolean(), nullable=True,
server_default=expression.true()))
def downgrade():
with op.batch_alter_table(u'entityproperties', schema=None) as batch_op:
batch_op.drop_column('bacnet_object')
Now when I try to downgrade to the base, I get an error stating that
no such column: entityproperties.bacnet_object
This error is generated while executing the base script(Script 1). I checked the generated SQL and it has
entityproperties.bacnet_object AS entityproperties_bacnet_object
Why is bacnet_object column is being asked for while executing script1? The downgrade of Script2 should remove the column from the EntityProperty table. What am I doing wrong here?
Update: I did check the db after the 2nd script is executed. There is no column called bacnet_object in EntityProperty table, but still the SQL generated is looking for a bacnet_object column?