1705
MySQLERRORCommonInnoDBHIGH confidence
Foreign key cascade depth exceeded maximum limit
Production Risk
High — DELETE or UPDATE fails mid-cascade; partial changes may be rolled back.
What this means
InnoDB limits the depth of cascading foreign key actions to 15 levels. Exceeding this limit causes the DML statement to fail.
Why it happens
- 1Deep chains of ON DELETE CASCADE or ON UPDATE CASCADE across many related tables.
- 2Circular or deeply nested FK relationships.
How to reproduce
trigger — this will error
trigger — this will error
-- Deleting from a root table that cascades through 16+ levels.
expected output
ERROR 1705 (HY000): Foreign key cascade delete/update exceeds max depth of 15.
Fix
Refactor the schema to reduce cascade depth
Refactor the schema to reduce cascade depth
-- Replace deep cascades with application-level deletion logic: -- Delete child records manually in reverse order before deleting the parent.
Why this works
Handling deletions in application code avoids the InnoDB cascade depth limit.
What not to do
✕
Sources
Official documentation ↗
MySQL 8.0 — 1705 ER_FK_DEPTH_EXCEEDED
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev