0

Hi there,

I created a new table and forgot to set the primary key with an auto_increment.

I went back and use:
ALTER TABLE table ADD PRIMARY KEY AUTO_INCREMENT (column);

However, now whenever I try to insert a new row of data, I get the error message "Duplicate entry '0' for primary key'.

It's obviously still not using the auto increment! I've checked that describe table; shows it with the auto_incremement, and I've also tried re-setting the value of auto_increment, but no luck.

Can anyone help?

2
Contributors
2
Replies
12
Views
2 Years
Discussion Span
Last Post by James_43
0

Yes. And I just discovered that that is what was causing the error.

Because the record I created before I set the auto_increment had a primary key = 0, when I added the auto_increment it got confused since it doesn't accept keys less than 0.

So I changed the id that was causing the issue and works fine now :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.