4113
MySQLERRORNotableHIGH confidence
Foreign key on generated column is not supported
Production Risk
Low — DDL fails with a clear error; no data is affected.
Why it happens
- 1A CREATE TABLE or ALTER TABLE attempted to add a foreign key referencing or using a generated column.
Fix
Use a stored (non-generated) column for the FK
Use a stored (non-generated) column for the FK
ALTER TABLE t ADD COLUMN fk_col INT, ADD FOREIGN KEY (fk_col) REFERENCES other(id);
Why this works
Regular stored columns are required for FK participation.
What not to do
✕
Sources
Official documentation ↗
MySQL 8.0 — 4113 ER_FK_ON_GENERATED_COLUMNS
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev