Akdes
Akdes

Reputation: 49

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

Upvotes: 0

Views: 7935

Answers (2)

koriander
koriander

Reputation: 3258

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.

Upvotes: 0

Riz
Riz

Reputation: 1131

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.

Upvotes: 1

Related Questions