简体   繁体   中英

ERROR 1075: Incorrect table definition; there can be only one auto column and it must be defined as a key

I try to "alter Table" I need one more AI field, not key... "List"

ID INT(11):PK Not Null AutoIn..
Name VARCHAR
UserID INT(11):FK Not Null
edit BOOL

and now i need one more field "sortpos" as AI. I try it with MySQL Workbench

ALTER TABLE `**mydb**`.`List` 
ADD COLUMN `sortpos` INT(11) NOT NULL AUTO_INCREMENT AFTER `edit`;

Can u help me?

Thx

You can't get better error message than this one. You already have ID defined as Auto Increment in your table. Now you are trying to add another field sortpos as auto increment which is not allowed. One table can only have one auto increment which must be defined as primary key.

Remove AUTO_INCREMENT from the alter statement and create a trigger to increment the new column.

Based on your comments, you are confusing user interface with table data. The table only needs to have one ID, if you want you can create a query like this:

SELECT ID, ID AS SORTPOS, NAME FROM List

But you don't even need a query for that, you should do it only at user interface level.

Plus, what you show in your comment is merely the heading of a list, not the list itself.

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