您好我有兩個表:外鍵約束的格式不正確 - 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身份運行查詢。 –
我加了我得到的錯誤 –