DBAtlas · Database operations atlas

1075: Incorrect table definition; there can be only one auto column and it must be defined as a key

MySQL

What does it mean?

The table definition is invalid because the AUTO_INCREMENT rules were violated: a table can have only one auto-increment column, and that column must be part of a key (PRIMARY KEY or UNIQUE/index).

Why does it happen?

Defining more than one AUTO_INCREMENT column, or leaving the AUTO_INCREMENT column out of every key (index). It occurs during CREATE TABLE or ALTER TABLE.

How to fix it

Keep a single AUTO_INCREMENT column and make it part of a key: CREATE TABLE t (id INT AUTO_INCREMENT PRIMARY KEY, ...); To fix an existing table, first add the column to a key: ALTER TABLE t ADD PRIMARY KEY (id); then define AUTO_INCREMENT. If you need more than one auto column, revisit the design; MySQL does not support it.

Open in DBAtlas →

More from this engine