So when trying to add an autoincrement to a field it comes up with #1062 – Duplicate entry ‘1’ for key 1 . I’ve tried removing the primary key and re-adding it and that works fine (which I assume wouldn’t if there was duplicates?)
But when I try to add an autoincrement to the field it throws an error. It gives me a browse option which runs the following SQL:
SELECT *
FROM `myTbl`
WHERE CONCAT_WS( "-", 11 ) = "1"
ORDER BY 11
LIMIT 0 , 30
However this returns a empty result set.. suggesting there are no duplicates. So if there are no duplicates, how come i can’t add an autoincrement?
Do you have any rows with value
0orNULLfor this column?ALTER TABLEcan cause primary keys to be resequenced. In the case of a key of 0, MySQL will try to give it the value 1, which will fail if the key 1 already exists.Try changing any
0orNULLvalues in the column to something higher (and unused).