dae dae - 6 months ago 63
Python Question

alembic for sqlalchemy doesn't detect column additions and removals

I defined the flowing model.

class JjfqServiceProvidorRecord(Base):
__tablename__ = 'jjfq_service_providor_record'
id = Column(Integer, primary_key=True)
phone = Column(String(16))
name = Column(String(20))


Then I ran
alembic revision --autogenerate -m 'first'
, and got the flowing migration file:

def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_table('jjfq_service_providor_record',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('phone', sa.String(length=16), nullable=True),
sa.Column('name', sa.String(length=20), nullable=True),
sa.PrimaryKeyConstraint('id')
)
### end Alembic commands ###

def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_table('jjfq_service_providor_record')
### end Alembic commands ###


And then, I delete the
name
field like this:

class JjfqServiceProvidorRecord(Base):
__tablename__ = 'jjfq_service_providor_record'
id = Column(Integer, primary_key=True)
phone = Column(String(16))
name = Column(String(20))


Then I reran
alembic revision --autogenerate -m 'second'
, the migration file generated by this command turn out to be:

def upgrade():
### commands auto generated by Alembic - please adjust! ###
pass
### end Alembic commands ###


def downgrade():
### commands auto generated by Alembic - please adjust! ###
pass
### end Alembic commands ###


What's wrong? Why didn't alembic detect column additions and removals?


python : Python 2.7.5

alembic : latest verison

sqlalchemy: 1.0

framework : falcon

system : Debian GNU/Linux 7

dae dae
Answer

Oh, Finally I found the problem. My sys.path point to the wrong directory where is an old version of my code. So every time I ran alembic revision --autogenerate, it reads from the old code which wasn't modified.