我正在尝试将数据加载到下表:
-- -----------------------------------------------------
-- Table `mydb`.`Gener`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Gener` (
`Movie_Name` VARCHAR(100) NOT NULL ,
`Genres_Type` VARCHAR(100) NULL ,
`Movie_Year` VARCHAR(100) NOT NULL ,
PRIMARY KEY (`Movie_Name`, `Movie_Year`) ,
CONSTRAINT `fk_Gener_Movie1`
FOREIGN KEY (`Movie_Name` , `Movie_Year` )
REFERENCES `mydb`.`Movie` (`Name` , `Year` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
-- -----------------------------------------------------
-- Table `mydb`.`Movie`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Movie` (
`Name` VARCHAR(100) NULL ,
`Lenght` INT(20) NULL ,
`Year` VARCHAR(100) NOT NULL ,
`id` INT(5) NOT NULL AUTO_INCREMENT ,
PRIMARY KEY (`id`, `Name`, `Year`) )
-- -----------------------------------------------------
-- Table `mydb`.`tempGener`
-- -----------------------------------------------------
CREATE TABLE `mydb`.`tempGener' (
`mGName` VARCHAR(100),
`mGType` VARCHAR(100),
`mGYear` VARCHAR(100)
)
我成功地将数据上传到以下两个表。
tempGener
,movie
.
现在我尝试Gener
使用以下命令将数据加载到我的表中,
INSERT INTO gener (Movie_Name, Genres_Type, Movie_Year)
(SELECT movie.Name, tempgener.mGType , movie.Year
FROM tempgener, movie)
但我收到以下错误:
错误代码:1452。无法添加或更新子行:外键约束失败(
mydb3
.gener
, CONSTRAINTfk_Gener_Movie1
FOREIGN KEY (Movie_Name
,Movie_Year
) REFERENCESmydb
.movie
(Name
,Year
) ON DELETE NO ACTION ON UPDATE NO ACTION)