0

Here is my current table design:

enter image description here

I have several columns and no KEYs set, so when I try the following command:

ALTER TABLE users MODIFY COLUMN id INT auto_increment;

it gives me an error. I want the id column in the table to auto-increment and I want it to start with 1.

AdamMc331
  • 16,492
  • 10
  • 71
  • 133
Huang Lee
  • 13
  • 3

2 Answers2

1

I think you are missing the primary key definition. Try this:

ALTER TABLE users MODIFY id INT AUTO_INCREMENT PRIMARY KEY

Also, I recommend you check this out.

Community
  • 1
  • 1
markus
  • 1,631
  • 2
  • 17
  • 31
  • 1
    Good answer. This should work. I think it's also important to mention that the reason this is required is because a column *CANNOT* be auto_increment if it is not a Primary Key. In OP's case, id is not a key, so that is why it cannot be altered to auto_increment alone. – AdamMc331 Dec 07 '14 at 22:37
  • Also, a funny thing to note (since you asked in the comments) I believe the error OP is getting is this: `Schema Creation Failed: Incorrect table definition; there can be only one auto column and it must be defined as a key: ` – AdamMc331 Dec 07 '14 at 22:41
0

You must specify PRIMARY_KEY with AUTO_INCREMENT:

ALTER TABLE users MODIFY id INT PRIMARY_KEY AUTO_INCREMENT;
Kevin Kopf
  • 13,327
  • 14
  • 49
  • 66