module-shipper icon indicating copy to clipboard operation
module-shipper copied to clipboard

Foreign key constraint fails

Open asuchalkin-space48 opened this issue 4 years ago • 2 comments

After upgrading Magento EE from version 2.3.4 to 2.4.4 and ShipperHQ module from 20.39.2 to 20.48.2 Magento throws error on setup:upgrade

In Mysql.php line 109:
                                                                                                                                                                                                          
  SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`upgrade`.`#sql-1524_8bc9`, CONSTRAINT `SHIPPERHQ_QUOTE_ADDR_DETAIL_QUO  
  TE_ADDR_ID_QUOTE_ADDR_ADDR_ID` FOREIGN KEY (`quote_address_id`) REFERENCES `quote_address` (`address_id`) ON DELET), query was: ALTER TABLE `shipperhq_quote_address_detail` MODIFY COLUMN `quote_addr  
  ess_id` int UNSIGNED NOT NULL   COMMENT "address id", ADD CONSTRAINT `SHIPPERHQ_QUOTE_ADDR_DETAIL_QUOTE_ADDR_ID_QUOTE_ADDR_ADDR_ID` FOREIGN KEY (`quote_address_id`) REFERENCES `quote_address` (`addr  
  ess_id`)  ON DELETE CASCADE                                                                                                                                                                             
                                                                                                                                                                                                          

In Mysql.php line 90:
                                                                                                                                                                                                          
  SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`upgrade`.`#sql-1524_8bc9`, CONSTRAINT `SHIPPERHQ_QUOTE_ADDR_DETAIL_QUO  
  TE_ADDR_ID_QUOTE_ADDR_ADDR_ID` FOREIGN KEY (`quote_address_id`) REFERENCES `quote_address` (`address_id`) ON DELET)

image

The problem is that table shipperhq_quote_address_detail was created using setup php script and column quote_address_id was varchar. In new module version with declarative schema column is changed to int and added foreign key. For some reason Magento doesn't apply all table changes, just adding foreign key and fails.

asuchalkin-space48 avatar Jun 30 '22 16:06 asuchalkin-space48

Thank you for the details. This has been passed to our dev team for further analysis.

wsajason avatar Jul 01 '22 10:07 wsajason

@asuchalkin-space48 if you are blocked by this issue, you can install version 20.45.7 and upgrade your database then install latest version.

20.45.7 is the most recent version before we introduced declarative schema installation. We'll also look to address this issue to handle the column type mismatch.

wsagen avatar Jul 22 '22 03:07 wsagen