3125
MariaDBERRORNotableDDLHIGH confidence

ALTER TABLE not supported: foreign key check requires table copy

Production Risk

Medium — ensure referential integrity is intact before adding FK constraints.

What this means

The foreign key constraints on the table must be validated during the ALTER, which requires a table copy and cannot proceed with ALGORITHM=INPLACE.

Why it happens
  1. 1Adding or modifying foreign key constraints requires referential integrity checks that prevent in-place DDL.
How to reproduce
trigger — this will error
trigger — this will error
ALTER TABLE child ADD CONSTRAINT fk1 FOREIGN KEY (pid) REFERENCES parent(id), ALGORITHM=INPLACE;

expected output

ERROR 3125 (HY000): ALGORITHM=INPLACE is not supported. Reason: Adding a foreign key requires table copy.

Fix

Use ALGORITHM=COPY

Use ALGORITHM=COPY
ALTER TABLE child ADD CONSTRAINT fk1 FOREIGN KEY (pid) REFERENCES parent(id), ALGORITHM=COPY;

Why this works

Allows full validation of referential integrity during rebuild.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 3125 ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_FK_CHECK2

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

← All MariaDB errors