1062: Duplicate entry for key
MySQLWhat does it mean?
The inserted or updated row violates a UNIQUE index or the PRIMARY KEY; the same key value already exists.
Why does it happen?
A repeated INSERT with the same unique key, duplicate data entry, an AUTO_INCREMENT counter that has fallen behind, or existing duplicate rows when adding a unique index to an existing table.
How to fix it
The error message shows the conflicting key value and the index name. To update the existing row, consider INSERT ... ON DUPLICATE KEY UPDATE or INSERT IGNORE / REPLACE. Find duplicates: SELECT my_column, COUNT(*) FROM my_table GROUP BY my_column HAVING COUNT(*) > 1. If you cannot add a unique index, clean up the duplicates first.