shipperhq / module-shipper

Base ShipperHQ Repo
Open Software License 3.0
21 stars 20 forks source link

Foreign key constraint fails #118

Closed asuchalkin-space48 closed 2 years ago

asuchalkin-space48 commented 2 years ago

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.

wsajason commented 2 years ago

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

wsagen commented 2 years ago

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