我对所有事情进行了多次检查,但无法找到帮助! 当我进行插入时,我一直收到这个错误代码我检查是否有任何拼写错误,但事实并非如此
Error Code: 1452. Cannot add or update a child row: a foreign key constraint fails (`crossfit`.`onderdeelpreworkout`,
CONSTRAINT `(FK_preworkout__(id_preworkout))2`
FOREIGN KEY (`FK_preworkout__(id_preworkout)`)
REFERENCES `preworkout` (`id_preworkout`) ON DELETE NO ACTION ON)
这是我创建的
-- -----------------------------------------------------
-- Table `CrossFit`.`preworkout`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `CrossFit`.`preworkout`;
CREATE TABLE IF NOT EXISTS `CrossFit`.`preworkout` (`id_preworkout` INT NOT NULL,
PRIMARY KEY (`id_preworkout`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `CrossFit`.`oefening`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `CrossFit`.`oefening` ;
CREATE TABLE IF NOT EXISTS `CrossFit`.`oefening` (
`naamoefening` VARCHAR(45) NOT NULL,
PRIMARY KEY (`naamoefening`),
UNIQUE INDEX `naamoefening_UNIQUE` (`naamoefening` ASC))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `CrossFit`.`onderdeelpreworkout`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `CrossFit`.`onderdeelpreworkout` ;
CREATE TABLE IF NOT EXISTS `CrossFit`.`onderdeelpreworkout` (
`FK_preworkout__(id_preworkout)` INT NOT NULL,
`FK_oefening__(naamoefening)` VARCHAR(45) NOT NULL,
`sets` INT NOT NULL,
`reps` INT NOT NULL,
`aantalminuten` INT NULL,
PRIMARY KEY (`FK_preworkout__(id_preworkout)`, `FK_oefening__(naamoefening)`),
INDEX `(FK_oefening__(naamoefening))1_idx` (`FK_oefening__(naamoefening)` ASC),
CONSTRAINT `(FK_preworkout__(id_preworkout))2`
FOREIGN KEY (`FK_preworkout__(id_preworkout)`)
REFERENCES `CrossFit`.`preworkout` (`id_preworkout`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `(FK_oefening__(naamoefening))1`
FOREIGN KEY (`FK_oefening__(naamoefening)`)
REFERENCES `CrossFit`.`oefening` (`naamoefening`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
和我的插页
-- Insert preworkout
INSERT INTO workoutofday VALUES (1);
INSERT INTO workoutofday VALUES (2);
INSERT INTO workoutofday VALUES (3);
INSERT INTO workoutofday VALUES (4);
INSERT INTO workoutofday VALUES (5);
-- Insert onderdeelpreworkout
INSERT INTO onderdeelpreworkout VALUES (1, 'Dipping', 40, 12, 89);
INSERT INTO onderdeelpreworkout VALUES (1, 'Leg press', 3, 15, 35);
INSERT INTO onderdeelpreworkout VALUES (1, 'Shoulder press', 5, 15, 100);
INSERT INTO onderdeelpreworkout VALUES (1, 'Squat', 4, 15, 80);
INSERT INTO onderdeelpreworkout VALUES (2, 'Kettlebell', 4, 15, 5);
INSERT INTO onderdeelpreworkout VALUES (2, 'Dumbel', 3, 15, 25);
INSERT INTO onderdeelpreworkout VALUES (2, 'Sit ups', 6, 15, 34);
INSERT INTO onderdeelpreworkout VALUES (2, 'Push ups', 6, 15, 23);
INSERT INTO onderdeelpreworkout VALUES (3, 'Bankdrukken', 4, 15, 70);
INSERT INTO onderdeelpreworkout VALUES (3, 'Kettlebell', 3, 12, 10);
INSERT INTO onderdeelpreworkout VALUES (3, 'Shoulder press', 3, 15, 30);
INSERT INTO onderdeelpreworkout VALUES (3, 'Dumbel', 3, 12, 15);