Mysql-向主键添加自动增量

Mysql-向主键添加自动增量,mysql,database,foreign-keys,auto-increment,Mysql,Database,Foreign Keys,Auto Increment,我对mysql有一个奇怪的问题 我试图改变一个表的列,该列是主键,并定义了自动增量约束。这也是多个其他表的外键引用。 我需要更改父级和所有子级中此列的长度 set foreign_key_checks=0; alter table Parent modify Identifier smallint(10) unsigned; alter table Child_1 modify FK_Identifier smallint(10) unsigned; alter table Child_2 m

我对mysql有一个奇怪的问题

我试图改变一个表的列,该列是主键,并定义了自动增量约束。这也是多个其他表的外键引用。 我需要更改父级和所有子级中此列的长度

set foreign_key_checks=0;
alter table Parent  modify Identifier smallint(10) unsigned;
alter table Child_1 modify FK_Identifier smallint(10) unsigned;
alter table Child_2 modify FK_Identifier smallint(10) unsigned;
alter table Child_3 modify FK_Identifier  smallint(10) unsigned;
alter table Child_4 modify FK_Identifier smallint(10) unsigned;
alter table Child_5 modify FK_Identifier smallint(10) unsigned;
set foreign_key_checks=1;
这将删除父表上的自动增量。将约束添加回去的最佳方法是什么

下面的例子似乎失败了

mysql> ALTER TABLE Parent MODIFY Identifier smallint(10) PRIMARY KEY AUTO_INCREMENT;
ERROR 1068 (42000): Multiple primary key defined


ALTER TABLE Parent MODIFY Identifier smallint(10) AUTO_INCREMENT;
------------------------
LATEST FOREIGN KEY ERROR
------------------------
110125 15:49:08 Error in foreign key constraint of table db/Child_1:
there is no index in referenced table which would contain
the columns as the first columns, or the data types in the
referenced table do not match to the ones in table. Constraint:
,
  CONSTRAINT Child_1_ibfk_1 FOREIGN KEY (FK_Identifier) REFERENCES RoomProfile (Identifier) ON DELETE CASCADE ON UPDATE CASCADE
The index in the foreign key in table is PRIMARY
有没有更好的方法来实现这一点

编辑:显示创建信息(更改后):

变身前

`Identifier` smallint(5) unsigned NOT NULL AUTO_INCREMENT,

谢谢

您不需要在MODIFY语句中指定
主键

ALTER TABLE Parent MODIFY Identifier smallint(10) AUTO_INCREMENT;

运行此设置时,是否可以发布
SHOW CREATE TABLE Parent
的结果,尝试禁用
foreign\u key\u checks
。设置set foreign\u key\u checks=0;并且运行上述操作没有任何效果:(数据类型中缺少unsigned:)@arnaud576875,奇怪,为什么我们不需要在
modify
语句中指定
PRIMARY KEY
?为什么键在被修改后仍然在周围?这根本不起作用!有人有办法吗?
ALTER TABLE Parent MODIFY Identifier smallint(10) AUTO_INCREMENT;