Frequently Asked Questions

Multiple Foreign Key Issue

For the following foreign Key issues

a:5:{i:0;s:508:"SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`abcdefg`.`ch_canadapost_quote_param`, CONSTRAINT `ch_canadapost_quote_param_ibfk_1` FOREIGN KEY (`magento_quote_id`) REFERENCES `sales_flat_quote` (`entity_id`) ON DELETE CAS), query was: REPLACE INTO `ch_canadapost_quote_param` (`magento_quote_id`, `signature`, `coverage`, `card_for_pickup`, `do_not_safe_drop`, `leave_at_door`, `cod`) VALUES (?, ?, ?, ?, ?, ?, ?)";i:1;s:3115:"


The simplest solution is to drop the foreign from the ch_canadapost tables in the database.


1. Connect to the database by SSH or using phpMyAdmin.

2. Use the SHOW CREATE TABLE command for these tables:

SHOW CREATE TABLE ch_canadapost_shipment;
SHOW CREATE TABLE ch_canadapost_quote_param;
SHOW CREATE TABLE ch_canadapost_shipment_link;
SHOW CREATE TABLE ch_canadapost_manifest_link;

3. Copy and paste the following ALTER TABLE commands to remove the foreign keys.

ALTER TABLE ch_canadapost_quote_param DROP FOREIGN KEY ch_canadapost_quote_param_ibfk_1;
ALTER TABLE ch_canadapost_shipment DROP FOREIGN KEY ch_canadapost_shipment_ibfk_1;
ALTER TABLE ch_canadapost_shipment_link DROP FOREIGN KEY ch_canadapost_shipment_link_ibfk_1;
ALTER TABLE ch_canadapost_manifest_link DROP FOREIGN KEY ch_canadapost_manifest_link_ibfk_1;

You must do this for each foreign key you see in the SHOW CREATE TABLE command.

Note: If you using phpMyAdmin, you can locate the foreign keys in those tables (ch_canadapost_quote_param and ch_canadapost_quote_param) and delete them using the UI.


4. Flush Magento's site cache and cache storage.

Note: If you have set table prefixes in your database, be sure to include those in the table names.
E.g. If the prefix is "abcd", the table and the FOREIGN KEY will be named abcd_ch_canadapost_quote_param


 Last updated Tue, Jul 8 2014 12:31pm

Be sure to browse our E-commerce Questions Section (FAQs), before opening a ticket.

Please Wait!

Please wait... it will take a second!