3109
MariaDBERRORNotableSchemaHIGH confidence

Generated column cannot reference an AUTO_INCREMENT column

Production Risk

Low — DDL fails; no table is created.

What this means

A generated column expression cannot reference an AUTO_INCREMENT column in the same table.

Why it happens
  1. 1Defining a generated column whose expression includes an AUTO_INCREMENT column.
How to reproduce
trigger — this will error
trigger — this will error
CREATE TABLE t (id INT AUTO_INCREMENT PRIMARY KEY, gen INT GENERATED ALWAYS AS (id * 2));

expected output

ERROR 3109 (HY000): Generated column 'gen' cannot refer to auto-increment column.

Fix

Remove the AUTO_INCREMENT reference from the generated expression

Remove the AUTO_INCREMENT reference from the generated expression
-- Use application logic or triggers to compute derived values from auto-increment columns

Why this works

Avoids the restriction by computing the derived value outside the generated column definition.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 3109 ER_GENERATED_COLUMN_REF_AUTO_INC2

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

← All MariaDB errors