Take the 2-minute tour ×

I have an sql query from my backup files, it has huge amount of insert statements.

INSERT INTO tns_spo_hotel (id_spo, id_hotel) VALUES (523,149),(523,195), ...

I have a foreign keys on both columns.

When i run this query, it returns

#1452 - Cannot add or update a child row: a foreign key constraint fails (`tsakhkad_tour_new`.`tns_spo_hotel`, CONSTRAINT `tns_spo_hotel_22` FOREIGN KEY (`id_hotel`) REFERENCES `tns_hotel` (`id`) ON DELETE CASCADE ON UPDATE CASCADE)

Because there are some rows, with missing values.

Is it possible to ignore that error message and continue sql execution ?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted


Short answer is No.

You can't ignore the error and continue with these invalid values. Because thats what the foreign keys constraints do. Thats why they called constraints. They ensure data consistency. If you could ignore these values that violate foreign key reference, your data becomes inconsistent.

The only possible way is to remove the foreign key constraint. But you shouldn't do that, fix your data entry instead.

share|improve this answer
... which you don't want to do. –  Ben Nov 3 '12 at 14:41
I realised! I was just adding something extra to your last sentence, which you've now done yourself :-). –  Ben Nov 3 '12 at 15:02
add comment

Your Answer


