Im using phpmyadmin for the first time and I get this error: incorrect table definition. there can be only one auto column and it must be defined as key. What am I doing wrong?
This is my code:
CREATE TABLE `database_reservering`.`formData` (
`nameTeacher` VARCHAR(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`nameChild` VARCHAR(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL , `email` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`age` INT(11) NOT NULL ,
`date` DATE NOT NULL ,
`comment` VARCHAR(300) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`id` INT(30) UNSIGNED NOT NULL AUTO_INCREMENT ,
PRIMARY KEY (`nameTeacher`)
) ENGINE = InnoDB;
3
Answers
The actual error message is:
The problem is that you have
id
as auto-increment, but the primary key is onnameTeacher
. This is not allowed. You can change the statement to makeid
the primary key, and put a unique constraint onnameTeacher
. This implements the same logic, but is valid MySQL syntax:Demo on DB Fiddle
Change
PRIMARY KEY (
nameTeacher
)to
PRIMARY KEY (
id
)Full statement:
What do you want to achieve when PK is set to the column other than AUTO_INCREMENT?
If you want to have separate independent autoincremented sequence for each
nameTeacher
value then alter the engine to MyISAM and define PK like(nameTeacher, id)
:fiddle
See Using AUTO_INCREMENT for details.