0

I just pushed up my Flask app to my staging environment and I noticed that I now have a discrepancy between the two Postgres databases. My staging database has an id column in the instance_tags table while my local database does not.

Three migrations ago I added an id column and then later removed it in models.py file. When it wasn't removing from my database, I ended up deleting it manually. I know, this is probably a bad thing! Anyway, my migration file looks like...

def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('instance_tags',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('instance_id', sa.String(length=30), nullable=False),
    sa.Column('tag_group', sa.String(length=50), nullable=True),
    sa.Column('tag', sa.String(length=50), nullable=True),
    sa.PrimaryKeyConstraint('id', 'instance_id', name=op.f('pk_instance_tags'))
    )

What is the best approach to remove the id column?

Thanks in advance for you help.

hugo
  • 1,175
  • 1
  • 11
  • 25

1 Answers1

0

It sounds like what you need is op.drop_column(...)

op.drop_column('instance_tags', 'id')
noslenkwah
  • 1,702
  • 1
  • 17
  • 26
  • Thanks for the reply. I'm familiar with the command. But, how do I generate this or where do I put this command? – hugo Sep 11 '18 at 00:57
  • If alembic did not already auto generate it then you have to add it manually to `upgrade()` (and a corresponding `add_column(...)` to `downgrade()`. Alembic's auto generation is very dependent on its configuration and is not a perfect "silver bullet". Consequently, it is advisable to review the auto generated migrations and make manual modifications as necessary before running them on your database. – noslenkwah Sep 11 '18 at 15:36