MySQL:修改列添加auto_increment:
MySQL: Modify column adding auto_increment:
我想更改 table 的列添加 auto_increment:
ALTER TABLE t_bed MODIFY COLUMN id BIGINT auto_increment;
这是错误:
Cannot change column 'id': used in a foreign key constraint 't_bed_ibfk_3' of table 't_room',
但是 table t_room 是空的
由于 t_room
table 是空的,您可以尝试简单地删除导致问题的外键约束:
ALTER TABLE t_room DROP FOREIGN KEY t_bed_ibfk_3;
然后 运行 您在 t_bed
table 上的更改语句使 id
成为自动递增列:
ALTER TABLE t_bed MODIFY COLUMN id BIGINT auto_increment;
最后,如果您仍然需要,可以在 t_room
table 中重新添加约束。
我想更改 table 的列添加 auto_increment:
ALTER TABLE t_bed MODIFY COLUMN id BIGINT auto_increment;
这是错误:
Cannot change column 'id': used in a foreign key constraint 't_bed_ibfk_3' of table 't_room',
但是 table t_room 是空的
由于 t_room
table 是空的,您可以尝试简单地删除导致问题的外键约束:
ALTER TABLE t_room DROP FOREIGN KEY t_bed_ibfk_3;
然后 运行 您在 t_bed
table 上的更改语句使 id
成为自动递增列:
ALTER TABLE t_bed MODIFY COLUMN id BIGINT auto_increment;
最后,如果您仍然需要,可以在 t_room
table 中重新添加约束。