'There can only be one column for primary key made up of two columns one is autoincremented

CREATE TABLE user (
    user_id SMALLINT NOT NULL AUTO_INCREMENT,
    name VARCHAR(50) NOT NULL,
    email VARCHAR(50) NOT NULL UNIQUE,
    PRIMARY KEY (user_id)
);

CREATE TABLE license (
    driver SMALLINT NOT NULL,
    license_number SMALLINT NOT NULL AUTO_INCREMENT,
    expirey_date timestamp NOT NULL,
    PRIMARY KEY (driver, license_number),
    FOREIGN KEY (driver) REFERENCES user(user_id)
);

Here I am getting the error

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

I want to define the license number to be autoincremented and part of the primary key at the same time but it is not letting me. My guessing is it because the primary key is a composite key made up of a foreign key as well.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source