1355
MySQLerrorddlhigh confidence
Duplicate foreign key constraint name
Production Risk
Low — DDL fails; no data affected.
What this means
Two foreign key constraints share the same name within the same database.
Why it happens
- 1Explicitly naming foreign keys with the same identifier
- 2Migration scripts that run CREATE TABLE with duplicate FK names
How to reproduce
trigger — this will error
trigger — this will error
ALTER TABLE t ADD CONSTRAINT fk_name FOREIGN KEY (col) REFERENCES ref(id); -- fk_name already exists
expected output
ERROR 1355 (HY000): Duplicate foreign key constraint name 'fk_name'
Fix
Use a unique constraint name
Use a unique constraint name
ALTER TABLE t ADD CONSTRAINT fk_t_col_2 FOREIGN KEY (col) REFERENCES ref(id);
Why this works
FK names must be unique within the database.
Sources
Official documentation ↗
MySQL 8.0 — 1355 ER_FK_DUP_NAME
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev