I have a code where I need a foreign key check disabled when updating. But I still need it to check for the foreign key but proceed anyways if the key is not found. The installation keeps breaking due to this.
$installthis->run("
ALTER TABLE `{$this->getTable('sweets/results')}`
ADD CONSTRAINT `FK_SWEETS_RESULTS_SWEET_ID_SWEETS_ID` FOREIGN KEY (`sweet_id`)
REFERENCES `{$this->getTable('sweets/sweets')}` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE;
ALTER TABLE `{$this->getTable('sweets/results_values')}`
ADD CONSTRAINT `FK_SWEETS_RESULTS_VALUES_RESULT_ID_SWEETS_RESULTS_ID` FOREIGN KEY (`result_id`)
REFERENCES `{$this->getTable('sweets/results')}` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE;
");
What do I need to change or add if I want it to proceed?
Edit: The error states that
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (
sweets_database
.sweets_results
, CONSTRAINTFK_SWEETS_RESULTS_SWEET_ID_SWEETS_ID
FOREIGN KEY (sweet_id
) REFERENCESsweets
(id
) ON DELETE CASCADE ON UPDATE CASCADE), query was: INSERT INTOsweets_results
(customer_id
,created_time
,update_time
) VALUES (?, '2018-11-02 05:35:24', '2018-11-02 05:35:24')