jualsevi
jualsevi

Reputation: 289

Insert dates in MySql Workbench

I have a error when I try to insert dates with MySql Workbenck

ERROR 1452: Cannot add or update a child row: a foreign key constraint fails (myfacebook.mensajes, CONSTRAINT CodigoRedDest FOREIGN KEY (Codigo) REFERENCES redessociales (Codigo) ON DELETE NO ACTION ON UPDATE NO ACTION)

SQL statement:

INSERT INTO `myfacebook`.`mensajes` (`Codigo`, `NickUsuario`, `CodigoRedDest`, `Mensaje`, `Fecha`) 
VALUES ('7', 'MaGo', '1', 'M7', '2013-09-23')

I'm beginner and I don't know what is the problem. If you need more dates about my tables, you say me.

Thanks for your answers.

Upvotes: 2

Views: 17084

Answers (1)

Franck Dernoncourt
Franck Dernoncourt

Reputation: 83207

One solution is to disable the foreign key check with SET FOREIGN_KEY_CHECKS:

SET FOREIGN_KEY_CHECKS=0;
INSERT INTO `myfacebook`.`mensajes` (`Codigo`, `NickUsuario`, `CodigoRedDest`, `Mensaje`, `Fecha`) 
VALUES ('7', 'MaGo', '1', 'M7', '2013-09-23')
SET FOREIGN_KEY_CHECKS=1;

Upvotes: 1

Related Questions