3105
MySQLERRORNotableSchemaHIGH confidence

Cannot specify a value for a generated column

Production Risk

Low — the INSERT/UPDATE fails; no data is written.

What this means

An INSERT or UPDATE attempted to supply an explicit value for a generated column, which is not permitted unless using DEFAULT.

Why it happens
  1. 1Specifying an explicit non-DEFAULT value in INSERT or UPDATE for a generated column.
How to reproduce
trigger — this will error
trigger — this will error
INSERT INTO t (id, gen_col) VALUES (1, 42);  -- gen_col is a generated column

expected output

ERROR 3105 (HY000): The value specified for generated column 'gen_col' in table 't' is not allowed.

Fix 1

Omit the generated column from the INSERT/UPDATE

Omit the generated column from the INSERT/UPDATE
INSERT INTO t (id) VALUES (1);

Why this works

MySQL automatically computes the generated column value.

Fix 2

Use DEFAULT if the column must be listed

Use DEFAULT if the column must be listed
INSERT INTO t (id, gen_col) VALUES (1, DEFAULT);

Why this works

DEFAULT explicitly requests MySQL to compute the generated value.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 3105 ER_NON_DEFAULT_VALUE_FOR_GENERATED_COLUMN2

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

← All MySQL errors