MySQL raises ER_DUP_KEYNAME when a CREATE or ALTER operation tries to add an index or constraint whose name already exists in the same table.
ER_DUP_KEYNAME (MySQL Error 1061: Duplicate key name) occurs when a CREATE TABLE, ALTER TABLE, or CREATE INDEX statement reuses an index name that already exists. Inspect current indexes with SHOW INDEX, then drop, rename, or guard the new index with IF NOT EXISTS to eliminate the conflict.
Duplicate key name '%s'
The error message "Duplicate key name '%s'" means MySQL refused to create or alter an index because another index with the same name already exists in the target table. The conflict can appear during CREATE TABLE, ALTER TABLE, CREATE INDEX, or when adding UNIQUE or PRIMARY KEY constraints. MySQL demands unique index names per table.
Leaving this error unresolved halts migrations, blocks deployments, and risks application downtime.
Understanding the root cause and fixing it quickly keeps CI pipelines green and ensures database consistency.
Most cases stem from running the same migration twice, forcing MySQL to recreate an index that is already present. Parallel feature branches may introduce two indexes with identical names. ORMs can also auto-generate index names that overlap with manually defined ones.
Foreign keys bring implicit indexes that clash with explicit definitions of the same column.
Begin by listing current indexes with SHOW INDEX. Decide whether to drop, rename, or skip creation of the duplicate index. Apply the chosen change using ALTER TABLE. Rerun the migration in a test environment, then deploy to production.
In Galaxy, the sidebar index list lets engineers verify names before committing schema changes.
Re-running a migration: wrap CREATE INDEX in IF NOT EXISTS to make it idempotent. Two migrations conflict: agree on a single, descriptive index name and adjust one file. Duplicate of an implicit foreign-key index: keep the implicit one or rename the explicit index.
Follow a naming convention such as idx_
_.
Automate schema diffs in CI to flag duplicate names pre-merge. Use Galaxy’s search to locate existing indexes fast. Enforce code reviews that check for duplicate index names. Guard new indexes with IF NOT EXISTS when possible.
Error 1062 "Duplicate entry" arises from duplicate data, not index names. Error 1005 "Can't create table" may wrap ER_DUP_KEYNAME when foreign keys fail. Error 1022 signals a similar duplicate key problem during ALTER TABLE.
Resolve the index conflict first to clear these errors.
.
No. MySQL rolls back the statement when the error occurs, leaving the table unchanged. You must resolve the duplicate before proceeding.
On case-insensitive file systems, names are treated as not case-sensitive, increasing the chance of duplicates. Always use exact matches.
Query INFORMATION_SCHEMA.STATISTICS or use SHOW INDEX for each table to list index names and columns.
Yes, since MySQL 8.0 the syntax CREATE INDEX IF NOT EXISTS prevents the duplicate key name error during idempotent migrations.