您好我有两张桌子:
select if => someday.Count > someday[-3].Count
我在尝试创建另一个错误时遇到错误:
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;
从Show Engine InnoDB状态我得到:
SQL Error (1005): Can't create table 'ev.userfilescategries' (errno:150)
Foreign key constraint is incorrectly formed
我想念什么?如何不正确地形成外键?
答案 0 :(得分:1)
创建这两个具有相同 COLLATE(utf8_general_ci)
的表格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` INT(11) NOT NULL AUTO_INCREMENT,
`createdAt` DATETIME NULL DEFAULT NULL,
`updatedAt` DATETIME NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `email` (`email`)
)
COLLATE='utf8_general_ci'
ENGINE=INNODB;
CREATE TABLE `userfilescategories` (
`name` VARCHAR(255) NULL DEFAULT NULL,
`user` INT(11) 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;
N:B:外键和引用键中的相应列必须具有相似的数据类型。整数类型的大小和符号必须相同。字符串类型的长度不必相同。对于非二进制(字符)字符串列,字符集和排序规则必须相同。