6
我正在尝试使用alembic将“主键”列添加到已有的MySQL表中。我尝试以下...将主键添加到alembic中的现有MySQL表中
op.add_column('mytable', sa.Column('id', sa.Integer(), nullable=False))
op.alter_column('mytable', 'id', autoincrement=True, existing_type=sa.Integer(), existing_server_default=False, existing_nullable=False)
而且得到了以下错误
sqlalchemy.exc.OperationalError: (OperationalError) (1075, 'Incorrect table definition; there can be only one auto column and it must be defined as a key') 'ALTER TABLE mytable CHANGE id id INTEGER NOT NULL AUTO_INCREMENT'()
看起来像由蒸馏器生成的ALTER语句的结尾没有添加PRIMARY KEY
的SQL语句。我可以错过一些设置吗?
在此先感谢!