// MySQL error reference
MySQL error 1061: Duplicate key name
CREATE INDEX or ALTER TABLE ADD INDEX uses an index name that already exists on that table.
- Error number
1061- Name
ER_DUP_KEYNAME- SQLSTATE
42000- Category
- Keys and constraints
What it means
Index names must be unique per table. Creating an index whose name is taken fails with 1061, even when the columns are different.
Common causes
- Re-running a migration that creates an index.
- Two migrations that create indexes with the same name.
How to fix it
-
List the table's indexes.
SHOW INDEX FROM orders;
-
Drop and recreate the index if the definition should change, or choose another name.
ALTER TABLE orders DROP INDEX idx_customer, ADD INDEX idx_customer (customer_id, created_at);
Related errors
1060Duplicate column name1826Duplicate foreign key constraint name1913SQL Server: Index or statistics name already exists
More keys and constraints errors
1062Duplicate entry for key1452Foreign 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.
// 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.