我尝试在“users”表上使用外键创建表“gallery”。 我已创建的表“用户”。如果我想创建“Gallery”表,我总会收到此错误消息。
用户:
CREATE TABLE users (
id int(11) NOT NULL AUTO_INCREMENT,
username varchar(255) NOT NULL,
password varchar(255) NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB;
空间:
CREATE TABLE gallery (
id INT(11) NOT NULL AUTO_INCREMENT,
name varchar(255) NOT NULL,
username varchar(255) NOT NULL,
PRIMARY KEY (id),
CONSTRAINT gallery_fk1
INDEX username (username),
FOREIGN KEY (username)
REFERENCES users(username)
ON DELETE CASCADE
) ENGINE=INNODB;
错误消息:
#1005 - Can't create table `gallery`.`gallery` (errno: 150 "Foreign key constraint is incorrectly formed")