Mysql - Add auto_increment to primary key(Mysql - 将 auto_increment 添加到主键)
问题描述
我的 mysql 有一个奇怪的问题.
I have a strange problem with mysql.
我正在尝试更改表的列,该列是主键并在其上定义了 auto_increment 约束.这也是多个其他表的外键引用.我需要在父项和所有子项中更改此列的长度.
I am trying to alter a table's column which is a primary key and has an auto_increment constraint defined on it. This is also a foreign key reference for multiple other tables. I need to change the length of this column in both , parent and all children.
这会删除父表上的自动增量.添加约束的最佳方法是什么?
This removes the auto increment on the parent table. What would be the best way to add the constraint back ?
以下似乎失败了.
有没有更好的方法来实现这一目标?
Is there a better way to achieve this ?
显示创建是(更改后):
Edit : Show create is (after alter) :
修改前
谢谢!
推荐答案
你不需要在MODIFY语句中指定PRIMARY KEY
:
You don't need to specify PRIMARY KEY
in the MODIFY statement:
这篇关于Mysql - 将 auto_increment 添加到主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!