简体   繁体   中英

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

Can the people of the internet help me with MySQL

Error

SQL query:

CREATE TABLE `users` (
`user_id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`username` VARCHAR( 32 ) NOT NULL ,
`password` VARCHAR( 32 ) NOT NULL ,
`first_name` VARCHAR( 32 ) NOT NULL ,
`last_name` VARCHAR( 32 ) NOT NULL ,
`email` VARCHAR( 1024 ) NOT NULL ,
`active` INT( 11 ) NOT NULL DEFAULT '0'
) ENGINE = innodb

MySQL said: Documentation

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

It clearly says in the error there can be only one auto column and it must be defined as a key .

Add PRIMARY KEY (user_id) at the end and it should work.

CREATE TABLE `users` (
`user_id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`username` VARCHAR( 32 ) NOT NULL ,
`password` VARCHAR( 32 ) NOT NULL ,
`first_name` VARCHAR( 32 ) NOT NULL ,
`last_name` VARCHAR( 32 ) NOT NULL ,
`email` VARCHAR( 1024 ) NOT NULL ,
`active` INT( 11 ) NOT NULL DEFAULT '0',
PRIMARY KEY (user_id)
) ENGINE = innodb;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM