3107
MySQLERRORNotableSchemaHIGH confidence
Generated column references a column defined after it
Production Risk
Low — DDL fails; no table is created.
What this means
A generated column expression references a column that is defined after it in the table definition, which is not permitted.
Why it happens
- 1Defining a generated column whose expression depends on a column listed later in CREATE TABLE.
How to reproduce
trigger — this will error
trigger — this will error
CREATE TABLE t (gen INT GENERATED ALWAYS AS (raw + 1), raw INT);
expected output
ERROR 3107 (HY000): Generated column 'gen' cannot refer to non-prior column 'raw'.
Fix
Define referenced columns before the generated column
Define referenced columns before the generated column
CREATE TABLE t (raw INT, gen INT GENERATED ALWAYS AS (raw + 1));
Why this works
MySQL evaluates generated columns in column order; prior columns must be defined first.
What not to do
✕
Sources
Official documentation ↗
MySQL 8.0 — 3107 ER_GENERATED_COLUMN_NON_PRIOR2
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev