我以前的模型:
class sample(Base):
__tablename__ = "sample"
id = Column(BigInteger, primary_key=True,index=True)
name = Column(String(30),index=True)
我的最新型号:
class sample(Base):
__tablename__ = "sample"
id = Column(String(length=1000), primary_key=True,index=True))
name = Column(String(30),index=True)
我运行了命令alembic revision --autogenerate -m "changed id field type to string"
我的迁移详细信息生成:
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))
升级 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 正在尝试删除现有索引并尝试创建另一个索引,但我不想再次创建或删除索引,直到该特定列发生任何更改。我怎样才能做到这一点?