我搜索的答案可能有效,但没有解决。
我已经创建了这样的表,当创建表“爱好”时出现错误 1072。
CREATE TABLE IF NOT EXISTS `project_r`.`user` (
`user_id` INT NOT NULL ,
`password` VARCHAR(45) NOT NULL ,
`RealName` VARCHAR(45) NOT NULL ,
`FamilyName` VARCHAR(45) NOT NULL ,
`birthdate` VARCHAR(45) NOT NULL ,
`Homecity` VARCHAR(45) NOT NULL ,
`school_id` INT NOT NULL ,
`school_enteryear` INT NOT NULL ,
`email` VARCHAR(45) NULL ,
`activestat` VARCHAR(45) NULL ,
`onlinestat` VARCHAR(45) NULL ,
`regtime` DATETIME NOT NULL ,
`avatar` VARCHAR(45) NULL ,
`status` VARCHAR(45) NULL ,
`desc` VARCHAR(45) NULL ,
`self_comment` VARCHAR(45) NULL ,
`userMsg_id` INT NOT NULL ,
PRIMARY KEY (`user_id`) ,
INDEX `fk_user_school1_idx` (`school_id` ASC) ,
CONSTRAINT `fk_user_school1`
FOREIGN KEY (`school_id` )
REFERENCES `project_r`.`school` (`school_id` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
然后创建表“爱好”
CREATE TABLE IF NOT EXISTS `project_r`.`hobbies` (
`hobby_user_id` INT NOT NULL ,
`favorite_music` VARCHAR(45) NULL ,
`favorite_game` VARCHAR(20) NULL ,
`favorite_film` VARCHAR(45) NULL ,
`favorite_book` VARCHAR(45) NULL ,
`favorite_sport` VARCHAR(45) NULL ,
`favorite_cartoon` VARCHAR(45) NULL ,
`hobby` VARCHAR(45) NULL ,
PRIMARY KEY (`user_id`) ,
INDEX `fk_user_id` (`hobby_user_id` ASC) ,
CONSTRAINT `fk_user_id`
FOREIGN KEY (`hobby_user_id` )
REFERENCES `project_r`.`user` (`user_id` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
添加或不添加 AUTO-INCREMENT 事物或添加到引用表的索引都不起作用。谢谢帮助。