我正在尝试使用alembic将'id'主键列添加到已存在的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)
Run Code Online (Sandbox Code Playgroud)
但得到以下错误
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' ()
Run Code Online (Sandbox Code Playgroud)
看起来像是由alembic生成的sql语句没有PRIMARY KEY在alter语句的末尾添加.我可以错过一些设置吗?
提前致谢!