1928
MariaDBERRORCriticalConstraintHIGH confidence
Foreign key constraint leads to a duplicate key
Production Risk
High — indicates a schema design issue; cascades may silently corrupt data in other scenarios.
What this means
An INSERT or UPDATE that cascades through a foreign key constraint results in a duplicate key violation in the parent or child table.
Why it happens
- 1ON UPDATE CASCADE triggers an update that produces a duplicate value in a UNIQUE column.
- 2Self-referential foreign key cascade creates a cycle ending in a duplicate.
How to reproduce
trigger — this will error
trigger — this will error
-- Cascading update causes duplicate in child table
expected output
ERROR 1928 (23000): Foreign key constraint leads to a duplicate key.
Fix
Redesign the data model to avoid cascading duplicates
Redesign the data model to avoid cascading duplicates
-- Use SET NULL or RESTRICT instead of CASCADE where cycles are possible
Why this works
Prevent cascades that can produce duplicate keys by choosing appropriate referential actions.
What not to do
✕
Sources
Official documentation ↗
MySQL 8.0 — 1928 ER_FOREIGN_DUPLICATE_KEY2
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev