简体   繁体   中英

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. 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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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