本文介绍了错误代码:1452.无法添加或更新子行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将数据加载到下表中:

I am trying to load data to following tables:

-- -----------------------------------------------------
-- 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)
)

我成功将数据上传到以下两个表.

I successfully uploading data to following two tables.

  • tempGener,
  • 电影.

现在我尝试使用以下命令将数据加载到我的 Gener 表中,

Now I trying to load data to my Gener table by using following command,

INSERT INTO gener (Movie_Name, Genres_Type, Movie_Year)
(SELECT movie.Name, tempgener.mGType , movie.Year
 FROM tempgener, movie)

但我收到以下错误:

错误代码:1452.无法添加或更新子行:外键约束失败 (mydb3.gener, CONSTRAINT fk_Gener_Movie1外键 (Movie_Name, Movie_Year) 参考 mydb.movie(Name, Year) ON DELETE NO Action ON UPDATE NO ACTION)

推荐答案

我解决了我的问题,问题是,我缺少 WHERE 语句.感谢每一个给我快速反应的机构.

I solve my problem, the problem was, I was missing WHERE statement.Thanks for every body giving me fast response.

这篇关于错误代码:1452.无法添加或更新子行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 12:42