MySQL 8.4Lab-verified · 2026-11-29

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

The AUTO_INCREMENT column is not (or would no longer be) the first column of any index.

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

Jump to a cause

  1. 01AUTO_INCREMENT in CREATE TABLE without PRIMARY KEY
  2. 02ALTER TABLE MODIFY ... AUTO_INCREMENT on a column with no key
  3. 03Moving the primary key off the AUTO_INCREMENT column

Lab-verifiedReproduced and fixed on MySQL 8.4.13 · 2026-11-29 · container image mysql:8.4

In MySQL an AUTO_INCREMENT column must be indexed: for example a PRIMARY KEY or a UNIQUE key on that column. ERROR 1075 appears when a CREATE TABLE or ALTER TABLE would leave the auto column without such a key.

The three runs below are the usual ways this happens. SHOW KEYS FROM table shows which keys exist before you change anything.

01AUTO_INCREMENT in CREATE TABLE without PRIMARY KEY

CREATE TABLE orders (id INT AUTO_INCREMENT, order_no VARCHAR(20), amount DECIMAL(10,2)) failed with ERROR 1075. The id column had AUTO_INCREMENT but no key.

Adding PRIMARY KEY to the id column fixed it. Two INSERTs without id then got 1 and 2.

Reproducerun as lab_a
CREATE TABLE orders (id INT AUTO_INCREMENT, order_no VARCHAR(20), amount DECIMAL(10,2));
✕ ERROR
ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key
Fixrun as lab_a
CREATE TABLE orders (id INT AUTO_INCREMENT PRIMARY KEY, order_no VARCHAR(20), amount DECIMAL(10,2));
OUTPUT
Query OK, 0 rows affected (0.02 sec)
After the fixrun as lab_a
INSERT INTO orders (order_no, amount) VALUES ('A-001', 100.00), ('A-002', 70.00);
SELECT * FROM orders;
✓ SUCCESS
Query OK, 2 rows affected (0.01 sec)
Records: 2  Duplicates: 0  Warnings: 0

+----+----------+--------+
| id | order_no | amount |
+----+----------+--------+
|  1 | A-001    | 100.00 |
|  2 | A-002    |  70.00 |
+----+----------+--------+
2 rows in set (0.00 sec)

02ALTER TABLE MODIFY ... AUTO_INCREMENT on a column with no key

customers had id INT NOT NULL but no key. ALTER TABLE customers MODIFY id INT NOT NULL AUTO_INCREMENT failed with 1075.

SHOW KEYS FROM customers returned Empty set, so there was no key at all. Making it the key in the same statement, MODIFY id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, succeeded. The next INSERT with only name got id 3, after the existing 1 and 2.

Setup
Setuprun as lab_a
CREATE TABLE customers (id INT NOT NULL, name VARCHAR(50));
INSERT INTO customers VALUES (1, 'Kim'), (2, 'Lee');
OUTPUT
Query OK, 0 rows affected (0.01 sec)

Query OK, 2 rows affected (0.01 sec)
Records: 2  Duplicates: 0  Warnings: 0
Reproducerun as lab_a
ALTER TABLE customers MODIFY id INT NOT NULL AUTO_INCREMENT;
✕ ERROR
ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key
Checkrun as lab_a
SHOW KEYS FROM customers;
OUTPUT
Empty set (0.00 sec)
Fixrun as lab_a
ALTER TABLE customers MODIFY id INT NOT NULL AUTO_INCREMENT PRIMARY KEY;
OUTPUT
Query OK, 2 rows affected (0.03 sec)
Records: 2  Duplicates: 0  Warnings: 0
After the fixrun as lab_a
INSERT INTO customers (name) VALUES ('Park');
SELECT * FROM customers;
✓ SUCCESS
Query OK, 1 row affected (0.00 sec)

+----+------+
| id | name |
+----+------+
|  1 | Kim  |
|  2 | Lee  |
|  3 | Park |
+----+------+
3 rows in set (0.00 sec)

03Moving the primary key off the AUTO_INCREMENT column

order_items.id was AUTO_INCREMENT PRIMARY KEY. Changing the primary key to (order_id, line_no) with ALTER TABLE order_items DROP PRIMARY KEY, ADD PRIMARY KEY (order_id, line_no) failed with 1075, because id would be left without a key.

Adding a unique key on id in the same ALTER, ..., ADD UNIQUE KEY uk_order_items_id (id), succeeded. SHOW KEYS then showed PRIMARY on order_id, line_no and uk_order_items_id on id, and a new INSERT worked.

Setup
Setuprun as lab_a
CREATE TABLE order_items (id INT AUTO_INCREMENT PRIMARY KEY, order_id INT NOT NULL, line_no INT NOT NULL);
INSERT INTO order_items (order_id, line_no) VALUES (10, 1), (10, 2), (11, 1);
OUTPUT
Query OK, 0 rows affected (0.01 sec)

Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0
Reproducerun as lab_a
ALTER TABLE order_items DROP PRIMARY KEY, ADD PRIMARY KEY (order_id, line_no);
✕ ERROR
ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key
Fixrun as lab_a
ALTER TABLE order_items DROP PRIMARY KEY, ADD PRIMARY KEY (order_id, line_no), ADD UNIQUE KEY uk_order_items_id (id);
OUTPUT
Query OK, 0 rows affected (0.05 sec)
Records: 0  Duplicates: 0  Warnings: 0
After the fixrun as lab_a
INSERT INTO order_items (order_id, line_no) VALUES (11, 2);
SHOW KEYS FROM order_items;
✓ SUCCESS
Query OK, 1 row affected (0.00 sec)

+-------------+------------+-------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
| Table       | Non_unique | Key_name          | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression |
+-------------+------------+-------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
| order_items |          0 | PRIMARY           |            1 | order_id    | A         |           2 |     NULL |   NULL |      | BTREE      |         |               | YES     | NULL       |
| order_items |          0 | PRIMARY           |            2 | line_no     | A         |           3 |     NULL |   NULL |      | BTREE      |         |               | YES     | NULL       |
| order_items |          0 | uk_order_items_id |            1 | id          | A         |           3 |     NULL |   NULL |      | BTREE      |         |               | YES     | NULL       |
+-------------+------------+-------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
3 rows in set (0.01 sec)

FAQ

How do I add AUTO_INCREMENT to an existing column in MySQL?

The column must be a key. If it is not one yet, add the key in the same statement: ALTER TABLE t MODIFY id INT NOT NULL AUTO_INCREMENT PRIMARY KEY;.

Does the AUTO_INCREMENT column have to be the primary key?

No. A UNIQUE key on it also works. In the third run, the primary key moved to (order_id, line_no) and UNIQUE KEY (id) kept id valid.

How do I change the primary key of a table with an AUTO_INCREMENT id?

Do it in one ALTER and keep a key on id: ALTER TABLE t DROP PRIMARY KEY, ADD PRIMARY KEY (a, b), ADD UNIQUE KEY (id);.

How do I check whether a column already has a key?

SHOW KEYS FROM t; lists every key and its columns. Empty set means the table has no keys.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary users created for the test, each with full rights on a database of the same name (its default database); root is the administrator. MySQL 8.4.13