// MySQL error reference

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
Error message
Duplicate entry '%s' for key '%s'

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

  1. 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

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.

// fewer errors, faster fixes

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.