1727
MySQLWARNINGNotableReplicationHIGH confidence

Unsafe statement: AUTO_INCREMENT column is not the first column in the index

Production Risk

Medium — AUTO_INCREMENT values may diverge on replicas.

What this means

A statement is flagged as unsafe for statement-based replication because the AUTO_INCREMENT column is not the first column of the primary or unique key, leading to potentially different values on source and replica.

Why it happens
  1. 1AUTO_INCREMENT column is part of a composite primary key but is not the leading column.
How to reproduce
trigger — this will error
trigger — this will error
CREATE TABLE t (a INT, b INT AUTO_INCREMENT, PRIMARY KEY (a, b));

expected output

Warning (Code 1727): Unsafe statement written to binary log using statement format. The AUTO_INCREMENT column is not the first column of the primary key.

Fix

Make AUTO_INCREMENT the leading column of the primary key

Make AUTO_INCREMENT the leading column of the primary key
CREATE TABLE t (b INT AUTO_INCREMENT, a INT, PRIMARY KEY (b, a));

Why this works

Ensuring AUTO_INCREMENT leads the PK guarantees deterministic value generation.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 1727 ER_BINLOG_UNSAFE_AUTOINC_NOT_FIRST

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

← All MySQL errors