MySQL error 1586: Duplicate entry for key (with key name)
The form of the duplicate-key error that names the index. It means the same as 1062: the value already exists in a unique index.
- Error number
1586- Name
ER_DUP_ENTRY_WITH_KEY_NAME- SQLSTATE
23000- Category
- Keys and constraints
What it means
1586 (ER_DUP_ENTRY_WITH_KEY_NAME) carries the message Duplicate entry '%s' for key '%s', with the key name rather than its number. The MySQL reference notes that 1062 is returned using this format string, so the text you see under 1062 comes from here. Treat it exactly like 1062.
Common causes
- Inserting or updating a row whose value already exists in a primary key or unique index.
How to fix it
-
Follow the steps for error 1062: find the existing row, upsert with
ON DUPLICATE KEY UPDATE, or skip duplicates.
Related errors
More keys and constraints errors
1061Duplicate key name1452Foreign key fails: cannot add child row1451Foreign key fails: cannot delete parent row1216Cannot add or update a child row1217Cannot delete or update a parent row1215Cannot add foreign key constraint3780Foreign key columns are incompatible1822Missing index for foreign key constraint
The code and message text are from the MySQL 8.4 Error Message Reference. Browse the full MySQL error list or search every database error.
Work on MySQL in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for MySQL and the other databases you use.