// MySQL error reference

MySQL error 1075: Only one auto column, and it must be a key

A table definition has an AUTO_INCREMENT column that isn't indexed, or more than one AUTO_INCREMENT column.

Error number
1075
Name
ER_WRONG_AUTO_KEY
SQLSTATE
42000
Category
Keys and constraints
Error message
Incorrect table definition; there can be only one auto column and it must be defined as a key

What it means

MySQL allows one AUTO_INCREMENT column per table, and it must be the first column of some index, usually the primary key. Violating either rule makes CREATE TABLE or ALTER TABLE fail with 1075.

Common causes

  • Declaring id INT AUTO_INCREMENT without making it a key.
  • Dropping the primary key from an AUTO_INCREMENT column.
  • Putting AUTO_INCREMENT on two columns.

How to fix it

  1. Make the column a key.

    CREATE TABLE notes (
        id INT NOT NULL AUTO_INCREMENT,
        body TEXT,
        PRIMARY KEY (id)
    );
  2. When changing the primary key, keep an index on the AUTO_INCREMENT column.

    ALTER TABLE notes DROP PRIMARY KEY, ADD PRIMARY KEY (id, created_at);

Related errors

More keys and constraints errors

The code and message text are from the MySQL 8.4 Error Message Reference. Browse the full MySQL error list or search every database error.

// fewer errors, faster fixes

Work on MySQL in SQLly

A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for MySQL and the other databases you use.