设置MySQL字段uid为auto_increment
由于某种原因,当我尝试将我的 uid 设置为 auto_increment 时,我不断收到以下错误。我正在使用 phpMyAdmin。
Error
SQL query:
ALTER TABLE `ITEMS` ADD `uid` INT( 2 ) NOT NULL AUTO_INCREMENT FIRST ,
ADD `name` VARCHAR( 100 ) NOT NULL AFTER `uid` ,
ADD `status` VARCHAR( 100 ) NOT NULL AFTER `name`
MySQL said: Documentation
#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key
我的数据库中有一些其他表,最初的索引为 auto_increment,但我将所有这些列更改为 uid varchar。但现在我要添加一个名为 ITEMS 的表,并且我希望 uid 成为“主”键,我可以将其用作所有其他表的参考点。
For some reason i keep getting the following error when i try to set my uid as auto_increment. I am using phpMyAdmin.
Error
SQL query:
ALTER TABLE `ITEMS` ADD `uid` INT( 2 ) NOT NULL AUTO_INCREMENT FIRST ,
ADD `name` VARCHAR( 100 ) NOT NULL AFTER `uid` ,
ADD `status` VARCHAR( 100 ) NOT NULL AFTER `name`
MySQL said: Documentation
#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key
I had a few other tables in my database that originally had index as auto_increment but I changed all those columns to uid varchar. But now I am adding a table named ITEMS and I want uid to be the "master" key that I can use as a reference point to all my other tables.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将 PRIMARY KEY 约束添加到新列。顺便说一句,这可能意味着从任何原来是 AUTO_INCRMENT 的旧列中删除该约束。
You need to add the PRIMARY KEY constraint to your new column. BTW, this may mean removing that constraint from any old column that was originally AUTO_INCREMENT.
您不是添加表,而是更改它。新规范与模式中存在的内容发生冲突,您可以执行 show table 并将其发布在这里供我们查看。
You're not adding a table, but changing it. New specification comes in conflict with what exists in the schema, you can do show table and post it here for us to see.