Skip to main content

What this error means

NO_UNIQUE_KEY means a table does not have a usable unique, not-null key. A PRIMARY KEY satisfies this requirement. A UNIQUE KEY can also satisfy it if every indexed column is NOT NULL and the key does not use a text/blob column or a prefix index. A common error message is:

Why PlanetScale rejects it

PlanetScale uses Vitess online schema change workflows to apply changes without downtime. Those workflows need a stable row identity while copying and reconciling data. Nullable unique keys do not qualify because MySQL allows multiple NULL values in a unique index. Without a primary key or a NOT NULL unique key, InnoDB uses an internal hidden row ID that is assigned independently on each MySQL instance, so it is not a shared identity across PRIMARY, REPLICA, and RDONLY tablets. Online DDL (VReplication) also needs a shared unique key between the source and target schemas, so adding the first primary key to a keyless table fails with found no possible unique key.

How to fix it

Define a primary key when you create the table. A PRIMARY KEY satisfies the unique, not-null key requirement.
If your only candidate key uses a TEXT, BLOB, or prefix index, use a surrogate key such as a bigint or UUID column instead.
If the table already exists and has no primary key or unique NOT NULL key, do not add an AUTO_INCREMENT primary key with a direct ALTER TABLE (including with safe migrations disabled):
That change can silently diverge data between tablets and lead to data loss during failover. Contact PlanetScale Support rather than adding the key yourself. See Tables without a primary key.

Need help?

Get help from the PlanetScale Support team, or join our Discord community to see how others are using PlanetScale.