#1452 - Cannot add or update a child row: a foreign key constraint fails No comprendo por que estoy recibiendo este error.Usando workbench tengo este EER.
Código:
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
CREATE SCHEMA IF NOT EXISTS `impgrupo_content` DEFAULT CHARACTER SET latin1 ;
USE `impgrupo_content` ;
-- -----------------------------------------------------
-- Table `impgrupo_content`.`client`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `impgrupo_content`.`client` (
`id` INT(33) NOT NULL AUTO_INCREMENT ,
`name` TEXT CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL ,
`code` VARCHAR(10) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL ,
`mail` VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL ,
PRIMARY KEY (`id`) )
ENGINE = MyISAM
AUTO_INCREMENT = 3
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_unicode_ci;
-- -----------------------------------------------------
-- Table `impgrupo_content`.`noticias`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `impgrupo_content`.`noticias` (
`id` INT(33) NOT NULL AUTO_INCREMENT ,
`tipo` INT(2) NOT NULL ,
`tittle` VARCHAR(210) NOT NULL ,
`url` TEXT NOT NULL ,
`datos` TEXT NOT NULL ,
`price` VARCHAR(2) NOT NULL ,
`autor` VARCHAR(50) NOT NULL ,
`noti` TEXT NOT NULL ,
`resume` TEXT NOT NULL ,
`mresume` TEXT NOT NULL ,
`map` VARCHAR(400) NOT NULL ,
`sec` TEXT NOT NULL ,
`ssec` TEXT NOT NULL ,
`date` VARCHAR(400) NOT NULL ,
`tt` TEXT NOT NULL ,
`stt` TEXT NOT NULL ,
`mun` TEXT NOT NULL ,
`rank` INT(2) NOT NULL ,
`kword` VARCHAR(600) NOT NULL ,
`addres` TEXT NOT NULL ,
`cover` TEXT NOT NULL ,
`img` VARCHAR(600) NOT NULL ,
`cimg` TEXT NOT NULL ,
`menu` VARCHAR(600) NOT NULL ,
`client` VARCHAR(100) NOT NULL ,
`des` VARCHAR(400) NOT NULL ,
`Slide` TINYINT(1) NOT NULL ,
`portd` TINYINT(1) NOT NULL ,
`book` INT(2) NOT NULL ,
`visible` TINYINT(1) NOT NULL ,
`logs` TEXT NOT NULL ,
PRIMARY KEY (`id`) ,
FULLTEXT INDEX `tittle` (`tittle` ASC) ,
FULLTEXT INDEX `noti` (`noti` ASC) ,
FULLTEXT INDEX `resume` (`resume` ASC) ,
FULLTEXT INDEX `mresume` (`mresume` ASC) ,
FULLTEXT INDEX `sec` (`sec` ASC) ,
FULLTEXT INDEX `ssec` (`ssec` ASC) ,
FULLTEXT INDEX `tt` (`tt` ASC) ,
FULLTEXT INDEX `mun` (`mun` ASC) ,
FULLTEXT INDEX `kword` (`kword` ASC) )
ENGINE = MyISAM
AUTO_INCREMENT = 685
DEFAULT CHARACTER SET = latin1;
-- -----------------------------------------------------
-- Table `impgrupo_content`.`client_user`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `impgrupo_content`.`client_user` (
`UserId` INT(33) NOT NULL AUTO_INCREMENT ,
`Uname` VARCHAR(40) NOT NULL ,
`pass` VARCHAR(40) NOT NULL ,
`name` VARCHAR(60) NOT NULL ,
`mail` VARCHAR(45) NOT NULL ,
`noticias_id` INT(33) NOT NULL ,
PRIMARY KEY (`UserId`, `noticias_id`) ,
UNIQUE INDEX `mail_UNIQUE` (`mail` ASC) ,
INDEX `fk_client_user_noticias1_idx` (`noticias_id` ASC) ,
CONSTRAINT `fk_client_user_noticias1`
FOREIGN KEY (`noticias_id` )
REFERENCES `impgrupo_content`.`noticias` (`id` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
AUTO_INCREMENT = 5
DEFAULT CHARACTER SET = latin1;
-- -----------------------------------------------------
-- Table `impgrupo_content`.`consumidor`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `impgrupo_content`.`consumidor` (
`ConsumidorId` INT(11) NOT NULL AUTO_INCREMENT ,
`nombre` VARCHAR(45) NOT NULL ,
`mail` VARCHAR(45) NOT NULL ,
`pass` VARCHAR(40) NOT NULL ,
`edad` DATE NOT NULL ,
`genero` INT(2) NOT NULL ,
PRIMARY KEY (`ConsumidorId`) ,
UNIQUE INDEX `mail_UNIQUE` (`mail` ASC) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;
-- -----------------------------------------------------
-- Table `impgrupo_content`.`horario`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `impgrupo_content`.`horario` (
`id` INT(33) NOT NULL AUTO_INCREMENT ,
`inicio` INT(11) NOT NULL ,
`final` INT(11) NOT NULL ,
`noticias_id` INT(33) NOT NULL ,
PRIMARY KEY (`id`) ,
INDEX `fk_horario_noticias1_idx` (`noticias_id` ASC) ,
CONSTRAINT `fk_horario_noticias1`
FOREIGN KEY (`noticias_id` )
REFERENCES `impgrupo_content`.`noticias` (`id` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;
-- -----------------------------------------------------
-- Table `impgrupo_content`.`reserva`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `impgrupo_content`.`reserva` (
`ReservaId` INT(11) NOT NULL AUTO_INCREMENT ,
`fecha` DATETIME NOT NULL ,
`nombre` VARCHAR(30) NOT NULL ,
`apellido` VARCHAR(30) NOT NULL ,
`tel` VARCHAR(9) NOT NULL ,
`email` VARCHAR(45) NOT NULL ,
`cantidad` INT(2) NOT NULL ,
`peticiones` TEXT NOT NULL ,
`enviado` TINYINT(1) NOT NULL DEFAULT '0' ,
`ConsumidorId` INT(11) NULL DEFAULT NULL ,
`noticias_id` INT(33) NOT NULL ,
PRIMARY KEY (`ReservaId`) ,
INDEX `fk_reserva_consumidor1_idx` (`ConsumidorId` ASC) ,
INDEX `fk_reserva_noticias1_idx` (`noticias_id` ASC) ,
CONSTRAINT `fk_reserva_consumidor1`
FOREIGN KEY (`ConsumidorId` )
REFERENCES `impgrupo_content`.`consumidor` (`ConsumidorId` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_reserva_noticias1`
FOREIGN KEY (`noticias_id` )
REFERENCES `impgrupo_content`.`noticias` (`id` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
AUTO_INCREMENT = 2
DEFAULT CHARACTER SET = latin1;
-- -----------------------------------------------------
-- Table `impgrupo_content`.`review`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `impgrupo_content`.`review` (
`ReviewId` VARCHAR(45) NOT NULL ,
`rating` TINYINT(4) NOT NULL ,
`comentario` TEXT NOT NULL ,
`ReservaId` INT(11) NOT NULL ,
`ConsumidorId` INT(11) NULL DEFAULT NULL ,
PRIMARY KEY (`ReviewId`) ,
INDEX `fk_review_reserva1_idx` (`ReservaId` ASC) ,
INDEX `fk_review_consumidor1_idx` (`ConsumidorId` ASC) ,
CONSTRAINT `fk_review_consumidor1`
FOREIGN KEY (`ConsumidorId` )
REFERENCES `impgrupo_content`.`consumidor` (`ConsumidorId` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_review_reserva1`
FOREIGN KEY (`ReservaId` )
REFERENCES `impgrupo_content`.`reserva` (`ReservaId` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;
USE `impgrupo_content` ;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
Ahora cuando trato de hacer este query me da un mensaje de error:
Código:
INSERT INTO `impgrupo_content`.`reserva` (
`ReservaId` ,
`fecha` ,
`nombre` ,
`apellido` ,
`tel` ,
`email` ,
`cantidad` ,
`peticiones` ,
`enviado` ,
`ConsumidorId` ,
`noticias_id`
)
VALUES (
NULL , '2013-01-17 00:00:00', 'Victor', 'Mendez', '22224444', '[email protected]', '2', 'ninguno', '0', NULL , '405'
MySQL said:
#1452 - Cannot add or update a child row: a foreign key constraint fails (`impgrupo_content`.`reserva`, CONSTRAINT `fk_reserva_noticias1` FOREIGN KEY (`noticias_id`) REFERENCES `noticias` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION)
estoy seguro que dicho id existepor que si realizo el query
Código:
SELECT * FROMM noticias WHERE id=405
entonces me selecciona el registro correctamente. Sinceramente no tengo idea de cual pudiera ser el problema, les agradeceria mucho si me pudieran ayudar con esto. |