我搜索的答案可能工作,但沒有解決。#1072鍵列不存在MySQL外鍵錯誤
我創建的表像這樣和創建表「愛好」時遇到錯誤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;
都自動遞增的事物或不是或索引添加到引用表不起作用。 thx尋求幫助。
thx,我的粗心。 –
沒問題! Upvote或接受答案,如果它有幫助! – Kraiden