3604
MariaDBERRORNotableDDLHIGH confidence

Default expression overrides GENERATED ALWAYS column

Production Risk

Low — Table creation or ALTER fails; no data is affected.

How to reproduce
trigger — this will error
trigger — this will error
CREATE TABLE t (a INT, b INT GENERATED ALWAYS AS (a * 2) DEFAULT 0);

expected output

ERROR 3604 (HY000): Default expression overrides generated always column.

Fix

Remove DEFAULT from generated column

Remove DEFAULT from generated column
CREATE TABLE t (a INT, b INT GENERATED ALWAYS AS (a * 2) STORED);

Why this works

Defines the generated column without a conflicting DEFAULT clause.

What not to do

Version notes

Sources
Official documentation ↗

MySQL 8.0 — 3604 ER_WRONG_DEFAULT_EXPRESSION_OVERRIDES_GENERATED_ALWAYS

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

← All MariaDB errors