1

My Previous Model:

class sample(Base):
    __tablename__ = "sample"
    id = Column(BigInteger, primary_key=True,index=True)
    name = Column(String(30),index=True)

My Latest Model:

class sample(Base):
    __tablename__ = "sample"
    id = Column(String(length=1000), primary_key=True,index=True))
    name = Column(String(30),index=True)

I ran the command alembic revision --autogenerate -m "changed id field type to string"

My migrations details generated:

def upgrade():
    op.create_index(op.f('ix_sample_name'), 'sample', ['name'], unique=False)
    op.drop_index('ix_sample_name', table_name='sample')
    op.alter_column('sample', 'id',
               existing_type=mysql.BIGINT(display_width=20),
               type_=sa.String(length=1000))

I am getting thefollowing error while upgrading head (alembic upgrade head ):

sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (1061, "Duplicate key name 'ix_userdetails_firstName'")
[SQL: CREATE INDEX `ix_userdetails_firstName` ON userdetails (`firstName`)]
(Background on this error at: http://sqlalche.me/e/e3q8)

Alembic is trying to drop existing index and trying to create another one, but i dont want to create or drop the index again until there is any change in that particular column. How can I achieve this??

L Shafiya
  • 31
  • 7

0 Answers0