1

I am trying to upgrade a magento store from magento 2.3.2 to Magento 2.3.2-p1

However I am stuck at the bin/magento setu:upgrade section with a SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails error.

So running bin/magento setup:db-schema:upgrade separately to verify also spits out the following

In Mysql.php line 110:

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`DBNAME`.`#sql-7d3_8c0ef`, CONSTRAINT `SALES_ORDER_CUSTOM
  ER_ID_CUSTOMER_ENTITY_ENTITY_ID` FOREIGN KEY (`customer_id`) REFERENCES `customer_entity` (`entity_id`) ON DELETE SET NULL), query was: ALTER TABLE `sales_order` MODIFY COLUMN `entity_
  id` int(10) UNSIGNED NOT NULL  AUTO_INCREMENT COMMENT "Entity ID", MODIFY COLUMN `store_id` smallint(5) UNSIGNED NULL   COMMENT "Store ID", MODIFY COLUMN `customer_id` int(10) UNSIGNED
   NULL   COMMENT "Customer ID", MODIFY COLUMN `billing_address_id` int(11)  NULL   COMMENT "Billing Address ID", MODIFY COLUMN `quote_address_id` int(11)  NULL   COMMENT "Quote Address
  ID", MODIFY COLUMN `quote_id` int(11)  NULL   COMMENT "Quote ID", MODIFY COLUMN `shipping_address_id` int(11)  NULL   COMMENT "Shipping Address ID", MODIFY COLUMN `increment_id` varcha
  r(32) NULL  COMMENT "Increment ID", MODIFY COLUMN `ext_customer_id` varchar(32) NULL  COMMENT "Ext Customer ID", MODIFY COLUMN `ext_order_id` varchar(32) NULL  COMMENT "Ext Order ID",
  MODIFY COLUMN `original_increment_id` varchar(32) NULL  COMMENT "Original Increment ID", MODIFY COLUMN `relation_child_id` varchar(32) NULL  COMMENT "Relation Child ID", MODIFY COLUMN
  `relation_child_real_id` varchar(32) NULL  COMMENT "Relation Child Real ID", MODIFY COLUMN `relation_parent_id` varchar(32) NULL  COMMENT "Relation Parent ID", MODIFY COLUMN `relation_
  parent_real_id` varchar(32) NULL  COMMENT "Relation Parent Real ID", MODIFY COLUMN `store_name` varchar(255) NULL  COMMENT "Store Name", MODIFY COLUMN `gift_message_id` int(11)  NULL
   COMMENT "Gift Message ID", ADD CONSTRAINT `SALES_ORDER_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID` FOREIGN KEY (`customer_id`) REFERENCES `customer_entity` (`entity_id`)  ON DELETE SET NUL
  L, ADD CONSTRAINT `SALES_ORDER_STORE_ID_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `store` (`store_id`)  ON DELETE SET NULL

In Mysql.php line 91:

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (DBANAME.#sql-7d3_8c0ef, CONSTRAINT SALES_ORDER_CUSTOM ER_ID_CUSTOMER_ENTITY_ENTITY_ID FOREIGN KEY (customer_id) REFERENCES customer_entity (entity_id) ON DELETE SET NULL)

0

By running

grep -r -l "SALES_ORDER_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID"

I was able to narrow down the db_schema.xml file responsible in the db update script when running

"bin/magento setup:upgrade"

As I was not able to find any relevant information and cross checking a similar error comment I found in researching the issue, I commented the following code in var/magento/module_sales/etc/db_schema.xml

comment out constriants from 253 to 268

<!--
        <constraint xsi:type="foreign" referenceId="SALES_ORDER_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID" table="sales_order"
                    column="customer_id" referenceTable="customer_entity" referenceColumn="entity_id"
                    onDelete="SET NULL"/>
        <constraint xsi:type="foreign" referenceId="SALES_ORDER_STORE_ID_STORE_STORE_ID" table="sales_order" column="store_id"
                    referenceTable="store" referenceColumn="store_id" onDelete="SET NULL"/>
-->

Then I restart server/ httpd

Finally

php bin/magento setup:upgrade

NO more error. However I believe this is a workaround fix until I am able to get better guidance from magento team.

1
  • Any updates here? – xpoback Apr 5 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.