MySQL Duplicate entry for key PRIMARY on Auto_Increment
Filed Under (Others, mysql) by admin on 14-12-2011
Tagged Under : mysql
Example errors:
“Duplicate entry ’123711155′ for key ‘PRIMARY’” or “Duplicate entry ’14676163′ for key ’1′”
Most likely this happens for tables with more than 5 million records
THE FIX
The fix is to use repair table
REPAIR TABLE <TABLE_NAME>;
Note: Sometimes the duplicate error is also caused by your field type having the maximum value already, for example in tinyint which has the maximum value of 127 so it better to use bigint for your auto ids, if this is not the case you can try the solution above.


