magento2: Magento 2.4 Upgrade issue Unable to apply data patch Magento\CatalogUrlRewrite\Setup\Patch\Data\UpdateUrlKeyForProducts
Preconditions (*)
- Magento 2.4.0
- Magento 2.4-develop
Steps to reproduce (*)
- Composer upgrade from 2.3.4 to 2.4.0
- php bin/magento setup:upgrade
Expected result (*)
- Successful upgrade
Actual result (*)
Module 'Magento_EavGraphQl':
Module 'Magento_Cms':
Module 'Magento_CatalogImportExport':
Module 'Magento_Catalog':
Module 'Magento_CatalogInventory':
Module 'Magento_Rule':
Module 'Magento_Payment':
Module 'Magento_CatalogRuleGraphQl':
Module 'Magento_CatalogRule':
Module 'Magento_CatalogUrlRewrite':
Unable to apply data patch Magento\CatalogUrlRewrite\Setup\Patch\Data\UpdateUrlKeyForProducts for module Magento_CatalogUrlRewrite. Original exception message: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a c
hild row: a foreign key constraint fails (`m24`.`catalog_product_entity_varchar`, CONSTRAINT `CAT_PRD_ENTT_VCHR_ENTT_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`entity_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CA), q
uery was: INSERT INTO `catalog_product_entity_varchar` (`value_id`,`value`) VALUES (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?
, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?),
(?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?)
, (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?,
?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?
, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?),
(?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?)
, (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?,
?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?
, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?),
(?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?)
, (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?,
?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?
, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?),
(?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?)
, (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?,
?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?
, ?), (?, ?), (?, ?), (?, ?), (?, ?) ON DUPLICATE KEY UPDATE `value` = VALUES(`value`)
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 8
- Comments: 51 (23 by maintainers)
Commits related to this issue
- Fixed Unable to apply data patch issue #29365 — committed to ravi-chandra3197/magento2 by ravi-chandra3197 4 years ago
- ENGCOM-8403: Fixed Unable to apply data patch issue after upgrade in 2.4 #29365 #29804 - Merge Pull Request magento/magento2#29804 from ravi-chandra3197/magento2:patch-29365 - Merged commits: 1.... — committed to magento/magento2 by magento-engcom-team 3 years ago
- ENGCOM-8403: Fixed Unable to apply data patch issue after upgrade in 2.4 #29365 #29804 — committed to magento/magento2 by gabrieldagama 3 years ago
@moni921 for now you can disable and re-enable foreign key constrain
…php $setup->getConnection()->query(‘SET @TEMPORARY_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=1’); $this->groupRepository->delete($customerGroup); $setup->getConnection()->query(‘SET FOREIGN_KEY_CHECKS=IF(@TEMPORARY_FOREIGN_KEY_CHECKS=0, 0, 1)’); …
We had the same issue when upgrading from 2.3.4 to 2.4.1. As someone else has mentioned, applying this pull request as a patch seemingly works.
Tagging @engcom-Echo in here, since he wrote that patch, maybe he has some more useful insights and can push for a quick fix to be added to Magento 2.4.1 or a hotfix to be released if it is deemed necessary 🙂
Please note that this patch is not working for commerce installations.
entity_id
is not a column name for commerce, it should berow_id
instead.For the update to succeed all keys should be included in the query. Change lines according below in Magento\CatalogUrlRewrite\Setup\Patch\Data\UpdateUrlKeyForProducts:
Can confirm issue. Upgrading from 2.3.5-p1 to 2.4.
I executed the SQL: SELECT COUNT(*) FROM catalog_product_entity_varchar cpev LEFT JOIN catalog_product_entity cpe on cpev.entity_id = cpe.entity_id WHERE cpe.entity_id IS NULL;
The result is 0
With the pull from @ravi-chandra3197 the upgrade works. https://github.com/magento/magento2/pull/29804/files
For anyone who needs a ready-to-use patch file for composer patches: here you go ->>> save it as patch file and configure it for composer patches, viola
✅ Confirmed by @engcom-Alfa Thank you for verifying the issue. Based on the provided information internal tickets
MC-40700
were createdIssue Available: @engcom-Alfa, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.
this seems to fix it
@ihor-sviziev : exactly the same problem …
@ihor-sviziev let me give it a try
@ihor-sviziev i solved this issue. So my database is upgraded succesfully. Any way, in my case the query is with row id.
SELECT COUNT(*) FROM catalog_product_entity_varchar cpev LEFT JOIN catalog_product_entity cpe on cpev.row_id = cpe.row_id WHERE cpe.row_id IS NULL;
Because i use Magento CE. Before the upgrade, i have some results with this query. So i removed it. Now the result is empty.
Can you provide more details? Which file are you changing?