4115
MySQLERRORNotableHIGH confidence

Referenced foreign key column has no unique index

Production Risk

Low — DDL fails; no data is modified.

Why it happens
  1. 1The referenced columns in the parent table do not have a UNIQUE or PRIMARY KEY constraint.
  2. 2The FK was defined referencing a non-key column.

Fix

Add a unique index on the referenced parent columns

Add a unique index on the referenced parent columns
ALTER TABLE parent ADD UNIQUE INDEX idx_col (col);

Why this works

A unique index on the referenced column satisfies the FK reference requirement.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 4115 ER_FK_NO_UNIQUE_INDEX_PARENT

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MySQL errors