简体   繁体   English

将MySQL字段uid设置为auto_increment

[英]setting MySQL field uid as auto_increment

For some reason i keep getting the following error when i try to set my uid as auto_increment. 由于某些原因,当我尝试将自己的uid设置为auto_increment时,我始终收到以下错误。 I am using phpMyAdmin. 我正在使用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. 我数据库中还有其他一些表,这些表最初的索引为auto_increment,但我将所有这些列都更改为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. 但是现在我要添加一个名为ITEMS的表,并且我希望uid成为“主”键,可以将其用作所有其他表的参考点。

You need to add the PRIMARY KEY constraint to your new column. 您需要将PRIMARY KEY约束添加到新列。 BTW, this may mean removing that constraint from any old column that was originally AUTO_INCREMENT. 顺便说一句,这可能意味着从任何原来是AUTO_INCREMENT的旧列中删除该约束。

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. 新规范与架构中存在的规范冲突,您可以显示表并将其发布在这里供我们查看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM