cancel
Showing results for 
Search instead for 
Did you mean: 

bin/magento setup:upgrade shows General error: 1823 Failed to add the foreign key constraint

bin/magento setup:upgrade shows General error: 1823 Failed to add the foreign key constraint

Hi,

I've copied historical sales/order data tables from CE 2.3.3 to a fresh installation of CE 2.3.4 database. Namely the following tables of the data tables. This made historical sales/order data available in new magento admin area. Now whenever I run bin/magento setup:upgrade command in CLI the following is displayed:

Schema creation/updates:
SQLSTATE[HY000]: General error: 1823 Failed to add the foreign key constraint 'database_name/QUOTE_STORE_ID_STORE_STORE_ID' to system tables, query was: ALTER TABLE `quote` MODIFY COLUMN `store_id` smallint(5) UNSIGNED NOT NULL DEFAULT 0 COMMENT "Store ID", MODIFY COLUMN `orig_order_id` int(10) UNSIGNED NULL DEFAULT 0 COMMENT "Orig Order ID", MODIFY COLUMN `customer_id` int(10) UNSIGNED NULL COMMENT "Customer ID", MODIFY COLUMN `customer_tax_class_id` int(10) UNSIGNED NULL COMMENT "Customer Tax Class ID", MODIFY COLUMN `customer_group_id` int(10) UNSIGNED NULL DEFAULT 0 COMMENT "Customer Group ID", MODIFY COLUMN `reserved_order_id` varchar(64) NULL COMMENT "Reserved Order ID", MODIFY COLUMN `gift_message_id` int(11) NULL COMMENT "Gift Message ID", ADD CONSTRAINT `QUOTE_STORE_ID_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `store` (`store_id`) ON DELETE CASCADE

 

sales_bestsellers_aggregated_daily
sales_bestsellers_aggregated_monthly
sales_bestsellers_aggregated_yearly
sales_creditmemo
sales_creditmemo_comment
sales_creditmemo_grid
sales_creditmemo_item
sales_invoice
sales_invoiced_aggregated
sales_invoiced_aggregated_order
sales_invoice_comment
sales_invoice_grid
sales_invoice_item
sales_order
sales_order_address
sales_order_aggregated_created
sales_order_aggregated_updated
sales_order_grid
sales_order_item
sales_order_payment
sales_order_status_history
sales_order_tax
sales_order_tax_item
sales_payment_transaction
sales_refunded_aggregated
sales_refunded_aggregated_order
sales_shipment
sales_shipment_comment
sales_shipment_grid
sales_shipment_item
sales_shipment_track
sales_shipping_aggregated
sales_shipping_aggregated_order
quote
quote_address
quote_address_item
quote_id_mask
quote_item
quote_item_option
quote_payment
quote_shipping_ratesequence_invoice_1sequence_order_1sequence_shipment_1sequence_creditmemo_1

 

Should I worry about this or is there anything that should be done to avoid this.

 

Thank you in advance.

6 REPLIES 6

Re: bin/magento setup:upgrade shows General error: 1823 Failed to add the foreign key constraint

Hello @cham_tale,

 

You can copy or move database tables to another version as you describe.

 

You must upgrade your Magento version with old version database.

 

Thank you

Hiren Patel

 

-----

Problem solved - Click on Kudos and Accept as Solution .

Re: bin/magento setup:upgrade shows General error: 1823 Failed to add the foreign key constraint

You should run this command: 

update quote set store_id = 0 where store_id not in (select store_id from store)

Please let me know if it works or give me a Like, Accept as a Solution!

Re: bin/magento setup:upgrade shows General error: 1823 Failed to add the foreign key constraint

SQLSTATE[HY000]: General error: 1823 Failed to add the foreign key constraint 'db_name/CAT_PRD_ENTT_INT_ATTR_ID_EAV_ATTR_ATTR_ID' to system tables, query was: ALTER TABLE `catalog_product_entity_int` ADD CONSTRAINT `CAT_PRD_ENTT_INT_ATTR_ID_EAV_ATTR_ATTR_ID` FOREIGN KEY (`attribute_id`) REFERENCES `eav_attribute` (`attribute_id`) ON DELETE CASCADE, ADD CONSTRAINT `CAT_PRD_ENTT_INT_ENTT_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`entity_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CASCADE, ADD CONSTRAINT `CATALOG_PRODUCT_ENTITY_INT_STORE_ID_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `store` (`store_id`) ON DELETE CASCADE, ADD CONSTRAINT `CATALOG_PRODUCT_ENTITY_INT_ENTITY_ID_ATTRIBUTE_ID_STORE_ID` UNIQUE KEY (`entity_id`,`attribute_id`,`store_id`), ADD INDEX `CATALOG_PRODUCT_ENTITY_INT_ATTRIBUTE_ID` (`attribute_id`),ADD INDEX `CATALOG_PRODUCT_ENTITY_INT_STORE_ID` (`store_id`), ADD INDEX `CATALOG_PRODUCT_ENTITY_INT_ATTRIBUTE_ID_STORE_ID_VALUE` (`attribute_id`,`store_id`,`value`)

Re: bin/magento setup:upgrade shows General error: 1823 Failed to add the foreign key constraint

same issue ..........

how to solve the problem...........

Re: bin/magento setup:upgrade shows General error: 1823 Failed to add the foreign key constraint

Please follow the below steps.

 

1. First please check in your database might be there should be same constraint with related table

2. if you found duplicate constraint than please drop it if possible

3. if not than drop the tables and run php bin/magento setup:upgrade command it will recreate it.

4. if you still facing same issue than you should disabled the extension which is cause the issue with duplicate of constraint.

 

Thank you
Anant Prajapati
Magento Certified Developer

Re: bin/magento setup:upgrade shows General error: 1823 Failed to add the foreign key constraint