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 ?
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.