您好我有两个表:外键约束的格式不正确 - mysql的
CREATE TABLE `user` (
`email` VARCHAR(255) NULL DEFAULT NULL,
`username` VARCHAR(255) NULL DEFAULT NULL,
`password` VARCHAR(255) NULL DEFAULT NULL,
`website` INT(11) NULL DEFAULT NULL,
`facebook_id` VARCHAR(255) NULL DEFAULT NULL,
`google_id` VARCHAR(255) NULL DEFAULT NULL,
`provider` VARCHAR(255) NULL DEFAULT NULL,
`getUpdates` TINYINT(1) NOT NULL,
`id` VARCHAR(60) NOT NULL,
`createdAt` DATETIME NULL DEFAULT NULL,
`updatedAt` DATETIME NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `email` (`email`)
)
COLLATE='hebrew_general_ci'
ENGINE=InnoDB;
我得到的错误试图创建另一个:
CREATE TABLE `userfilescategories` (
`name` VARCHAR(255) NULL DEFAULT NULL,
`user` VARCHAR(60) NOT NULL,
`id` INT(11) NOT NULL AUTO_INCREMENT,
`createdAt` DATETIME NULL DEFAULT NULL,
`updatedAt` DATETIME NULL DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `user` (`user`),
CONSTRAINT `UserFilesCategories_Users_FK` FOREIGN KEY (`user`) REFERENCES `user` (`id`) ON DELETE CASCADE
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=6;
我得到的错误是:
SQL Error (1005): Can't create table 'ev.userfilescategries' (errno:150)
Foreign key constraint is incorrectly formed
从Show Engine InnoDB状态我得到:
Error in foreign key constraint of table ev/userfilescategories:
FOREIGN KEY (`user`) REFERENCES `user` (`id`) ON DELETE CASCADE
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=6:
Cannot find an index in the referenced table where the referenced columns appear as the first columns, or column types in the table and the referenced table do not match for constraint.
Note that the internal storage type of ENUM and SET changed in tables created with >= InnoDB-4.1.12, and such columns in old tables cannot be referenced by such columns in new tables.
我错过了什么?外键如何形成不正确?
您可以发布您收到的错误消息吗? –
针对确切的错误消息运行'show engine innodb status'。您可能需要以root身份运行查询。 –
我加了我得到的错误 –