Forum Moderators: coopster
The problem is, that on rare occassions this fails because the auto-increment value of the primary key eg. 127, is already in the table taken by another record. I should mention that the id field (primary key, auto-increment) is never manually inserted, I always pass a blank value for auto-increment to take care of it.
Is this some kind of MySQL bug, or could it have something to do with my DELETE before inserting again?
Thanks for your reply
My guess is that you are successful whenever you are deleting all the rows in your table, otherwise it should fail...
If you delete the row containing the maximum value for anAUTO_INCREMENTcolumn, the value will be reused...If you delete all rows in the table withDELETE FROM tbl_name(without aWHERE) inAUTOCOMMITmode, the sequence starts over...Resource: CREATE TABLE [mysql.com]
>>Is this some kind of MySQL bug...
No. MySQL will set it to the next sequence value. Typically this is
value+1, where
valueis the largest value for the column currently in the table.
Have you considered changing the column from type
TINYINTto
INT? ......and I would also make it
SIGNED.