
from sqlalchemy import Column, Integer, String, MetaData, Table

meta = MetaData()


#
# Tables to alter
#
#

instance_id = Column('instance_id', Integer())
instance_uuid = Column('instance_uuid', String(255))


def upgrade(migrate_engine):
    meta.bind = migrate_engine
    migrations = Table('migrations', meta, autoload=True)
    migrations.create_column(instance_uuid)
    migrations.c.instance_id.drop()


def downgrade(migrate_engine):
    meta.bind = migrate_engine
    migrations = Table('migrations', meta, autoload=True)
    migrations.c.instance_uuid.drop()
    migrations.create_column(instance_id)


from sqlalchemy import Column, Integer, String, MetaData, Table


meta = MetaData()


#
# Tables to alter
#
#

instance_id = Column('instance_id', Integer())
instance_uuid = Column('instance_uuid', String(255))


def upgrade(migrate_engine):
    meta.bind = migrate_engine
    migrations = Table('migrations', meta, autoload=True)
    migrations.create_column(instance_uuid)

    if migrate_engine.name == "mysql":
        migrate_engine.execute("ALTER TABLE migrations DROP FOREIGN KEY " \
                "`migrations_ibfk_1`;")

    migrations.c.instance_id.drop()


def downgrade(migrate_engine):
    meta.bind = migrate_engine
    migrations = Table('migrations', meta, autoload=True)
    migrations.c.instance_uuid.drop()
    migrations.create_column(instance_id)

Drop FK before dropping instance_id column.
Drop FK before dropping instance_id column.
  
  from sqlalchemy import Column, Integer, String, MetaData, Table
+ 
  
  meta = MetaData()
  
  
  #
  # Tables to alter
  #
  #
  
  instance_id = Column('instance_id', Integer())
  instance_uuid = Column('instance_uuid', String(255))
  
  
  def upgrade(migrate_engine):
      meta.bind = migrate_engine
      migrations = Table('migrations', meta, autoload=True)
      migrations.create_column(instance_uuid)
+ 
+     if migrate_engine.name == "mysql":
+         migrate_engine.execute("ALTER TABLE migrations DROP FOREIGN KEY " \
+                 "`migrations_ibfk_1`;")
+ 
      migrations.c.instance_id.drop()
  
  
  def downgrade(migrate_engine):
      meta.bind = migrate_engine
      migrations = Table('migrations', meta, autoload=True)
      migrations.c.instance_uuid.drop()
      migrations.create_column(instance_id)
  
Drop FK before dropping instance_id column.
## Code Before:

from sqlalchemy import Column, Integer, String, MetaData, Table

meta = MetaData()


#
# Tables to alter
#
#

instance_id = Column('instance_id', Integer())
instance_uuid = Column('instance_uuid', String(255))


def upgrade(migrate_engine):
    meta.bind = migrate_engine
    migrations = Table('migrations', meta, autoload=True)
    migrations.create_column(instance_uuid)
    migrations.c.instance_id.drop()


def downgrade(migrate_engine):
    meta.bind = migrate_engine
    migrations = Table('migrations', meta, autoload=True)
    migrations.c.instance_uuid.drop()
    migrations.create_column(instance_id)

## Instruction:
Drop FK before dropping instance_id column.
## Code After:

from sqlalchemy import Column, Integer, String, MetaData, Table


meta = MetaData()


#
# Tables to alter
#
#

instance_id = Column('instance_id', Integer())
instance_uuid = Column('instance_uuid', String(255))


def upgrade(migrate_engine):
    meta.bind = migrate_engine
    migrations = Table('migrations', meta, autoload=True)
    migrations.create_column(instance_uuid)

    if migrate_engine.name == "mysql":
        migrate_engine.execute("ALTER TABLE migrations DROP FOREIGN KEY " \
                "`migrations_ibfk_1`;")

    migrations.c.instance_id.drop()


def downgrade(migrate_engine):
    meta.bind = migrate_engine
    migrations = Table('migrations', meta, autoload=True)
    migrations.c.instance_uuid.drop()
    migrations.create_column(instance_id)
