When I was importing a bunch of records from CSVs into a MySQL database, at some point I ran into an intriguing issue. Totally legit, but still strange in the way it shows up:
#1062 - Duplicate entry '127' for key 'PRIMARY'
How can the AUTO_INCREMENT’ed primary key be duplicated?
My table is pretty straightforward: some
ints, a couple of
The important detail here is the primary key, the typical
id that is generally the first field. Turns out, for some reason I set it as tinyint(4) when I created the table, thinking it would be enough, being the table not supposed to be big. As this table shows, the maximum value for signed tinyint is 127, just like the error message reported. When MySQL tries to increase that value, the field is capped to 127 and it reports the duplication issue.
The solution is to simply set it a bigger cap value. A
int will work fine for now.