3204
MariaDBERRORNotableDDLHIGH confidence
Invalid default expression for generated column
Production Risk
Low — DDL error.
Why it happens
- 1Specifying an explicit DEFAULT value on a generated column, which is not permitted.
- 2Generated columns derive their value from the expression; no DEFAULT is allowed.
How to reproduce
trigger — this will error
trigger — this will error
ALTER TABLE t1 ADD COLUMN gc INT AS (col1 * 2) VIRTUAL DEFAULT 0;
expected output
ERROR 3204 (HY000): Generated column cannot have a default value.
Fix
Remove the DEFAULT clause
Remove the DEFAULT clause
ALTER TABLE t1 ADD COLUMN gc INT AS (col1 * 2) VIRTUAL;
Why this works
Generated columns do not accept DEFAULT; their value is computed.
What not to do
✕
Sources
Official documentation ↗
MySQL 8.0 — 3204 ER_INVALID_DEFAULT_EXPR_GENERATED_COLUMN
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev