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(BigInteger, primary_key=True,index=True)
    name = Column(String(30),index=True)

I ran the command alembic revision --autogenerate -m "changed Name field to name"

My migrations details generated:

def upgrade():

op.add_column('sample', sa.Column('name', sa.String(length=1000), nullable=False))
op.drop_column('sample', 'Name')

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

    sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (1060, "Duplicate column name 'name'")
[SQL: ALTER TABLE sampleADD COLUMN `name` VARCHAR(1000) NOT NULL]
(Background on this error at: http://sqlalche.me/e/e3q8)

Alembic is trying to drop existing column and trying to create new column, but i want to update the particular column. How can I achieve this??

L Shafiya
  • 31
  • 7

1 Answers1

0

You probably want alter_column:

op.alter_column('sample', 'Name', new_column_name='name')