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.

How to fix it

Add a primary key or a unique key over columns that are all declared NOT NULL.
If the table already exists and the intended key column contains NULL values, fix the data first, then make the column NOT NULL, then add the unique key. For large tables, split those steps into separate deploy requests.
If your only candidate key uses a TEXT, BLOB, or prefix index, use a surrogate key such as a bigint or UUID column instead.

Need help?

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