2

While saving new product in admin panel I am getting this error "Unique constraint violation found"

Exception Log of this error:

Unique constraint violation found {"exception":"[object] (Magento\Framework\Exception\AlreadyExistsException(code: 0): Unique constraint violation found at /chroot/home/hannahha/esto.co.uk/html/shop/vendor/magento/framework/EntityManager/Operation/Create.php:134, Magento\Framework\DB\Adapter\DuplicateException(code: 1062): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '4294967295' for key 'PRIMARY', query was: INSERT INTO catalog_product_entity (entity_id, attribute_set_id, type_id, sku, has_options, required_options, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)

0

After a lot of debugging I found the issue, I had and custom module in which I was injecting some custom functionality on the observer "catalog_product save_commit_after", which have some bug and was crashing. Due to which this error was occurring.

To fix this, I removed the bug from my custom module and after this I opened the "catalog_product_entity" table in phpmyadmin and removed the the record with the key mentioned in the exception error.

This fixed my issue.

0

I had this issue after upgrading to Magento ECE 2.4.1, ElasticSearch 7 and MariaDb 10.2. The solution was the following patch, provided by Magento.

Add this code to {project_root}/m2-hotfixes/MDVA-33606_EE_2.4.1_v1.composer.patch

diff --git a/vendor/magento/module-versions-cms/Block/Adminhtml/Cms/Page/Edit/Tab/Hierarchy.php b/vendor/magento/module-versions-cms/Block/Adminhtml/Cms/Page/Edit/Tab/Hierarchy.php
index 72996f7476d..6426aed16d5 100644
--- a/vendor/magento/module-versions-cms/Block/Adminhtml/Cms/Page/Edit/Tab/Hierarchy.php
+++ b/vendor/magento/module-versions-cms/Block/Adminhtml/Cms/Page/Edit/Tab/Hierarchy.php
@@ -6,6 +6,7 @@
 namespace Magento\VersionsCms\Block\Adminhtml\Cms\Page\Edit\Tab;
 
 use Magento\Store\Model\StoreManagerInterface;
+use Magento\VersionsCms\Model\Hierarchy\Node;
 
 /**
  * Cms Page Edit Hierarchy Tab Block
@@ -163,15 +164,15 @@ class Hierarchy extends \Magento\Backend\Block\Template implements \Magento\Back
                 }
             } else {
                 foreach ($collection as $item) {
-                    if ($item->getLevel() == \Magento\VersionsCms\Model\Hierarchy\Node::NODE_LEVEL_FAKE) {
+                    if ($item->getLevel() == Node::NODE_LEVEL_FAKE) {
                         continue;
                     }
-                    /* @var $item \Magento\VersionsCms\Model\Hierarchy\Node */
+                    /* @var $item Node */
                     $node = [
                         'node_id' => $item->getId(),
                         'parent_node_id' => $item->getParentNodeId(),
                         'label' => $item->getLabel(),
-                        'store_label' => $this->getNodeStoreName((int)$item->getScopeId()),
+                        'store_label' => $this->getNodeStoreName((int)$item->getScopeId(), $item->getScope()),
                         'page_exists' => (bool)$item->getPageExists(),
                         'page_id' => $item->getPageId(),
                         'current_page' => (bool)$item->getCurrentPage(),
@@ -188,12 +189,18 @@ class Hierarchy extends \Magento\Backend\Block\Template implements \Magento\Back
      * Return store name for node by scope_id
      *
      * @param int $scopeId
+     * @param string $scopeCode
      * @return string
      * @throws \Magento\Framework\Exception\NoSuchEntityException
      */
-    private function getNodeStoreName(int $scopeId)
+    private function getNodeStoreName(int $scopeId, string $scopeCode = Node::NODE_SCOPE_STORE)
     {
-        $scope = $this->storeManager->getStore($scopeId);
+        if ($scopeCode === Node::NODE_SCOPE_WEBSITE) {
+            $scope = $this->storeManager->getWebsite($scopeId);
+        } else {
+            $scope = $this->storeManager->getStore($scopeId);
+        }
+
         if (!$scope->getId()) {
             return 'All Store Views';
         }
diff --git a/vendor/magento/module-versions-cms/Observer/Backend/CmsPageSaveAfterObserver.php b/vendor/magento/module-versions-cms/Observer/Backend/CmsPageSaveAfterObserver.php
index f60f078a763..9327551c2e5 100644
--- a/vendor/magento/module-versions-cms/Observer/Backend/CmsPageSaveAfterObserver.php
+++ b/vendor/magento/module-versions-cms/Observer/Backend/CmsPageSaveAfterObserver.php
@@ -11,6 +11,7 @@ use Magento\Framework\Event\ObserverInterface;
 use Magento\Framework\Exception\LocalizedException;
 use Magento\Store\Model\ScopeInterface;
 use Magento\Store\Model\ScopeResolver;
+use Magento\Store\Model\Store;
 use Magento\VersionsCms\Helper\Hierarchy;
 use Magento\VersionsCms\Model\Hierarchy\Node as HierarchyNode;
 use Magento\VersionsCms\Model\ResourceModel\Hierarchy\Node;
@@ -131,7 +132,7 @@ class CmsPageSaveAfterObserver implements ObserverInterface
                 continue;
             }
 
-            $requestUrl = $parentNode->getIdentifier() . '/' . $page->getIdentifier();
+            $requestUrl = $parentNode->getRequestUrl() . '/' . $page->getIdentifier();
             if ($this->isNodeExist($requestUrl, $nodeScopeId, (int)$parentNode->getId(), (int)$page->getId())) {
                 throw new LocalizedException(
                     __(
@@ -167,6 +168,9 @@ class CmsPageSaveAfterObserver implements ObserverInterface
         }
 
         foreach ($pageStoreIds as $storeId) {
+            if ((int)$storeId === Store::DEFAULT_STORE_ID) {
+                return true;
+            }
             $isScopeValid = $this->scopeResolver->isBelongsToScope(
                 $nodeScope,
                 $nodeScopeId,
@@ -193,10 +197,6 @@ class CmsPageSaveAfterObserver implements ObserverInterface
     private function createNewNode(HierarchyNode $parentNode, array $pageData, int $sortOrder, string $pageIdentifier)
     {
         $newNode = clone $parentNode;
-        if ($parentNode->getScopeId() !== HierarchyNode::NODE_SCOPE_DEFAULT_ID) {
-            $newNode->setScope(HierarchyNode::NODE_SCOPE_STORE);
-        }
-        $newNode->setScopeId($parentNode->getScopeId());
 
         $newNode->addData(
             $pageData

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.