0

After installing meta module from https://github.com/magento/meta-for-magento2 and running

php bin/magento setup:upgrade 

I get an error

Unable to apply data patch Meta\Catalog\Setup\Patch\Data\AddProductAttributes for module Meta_Catalog.<br>Original exception message: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '4-General' for key 'eav_attribute_group.EAV_ATTRIBUTE_GROUP_ATTRIBUTE_SET_ID_ATTRIBUTE_GROUP_NAME', query was: UPDATE `eav_attribute_group` SET `attribute_set_id` = ?, `attribute_group_name` = ?, `default_id` = ? WHERE (`attribute_group_id`='45')

How do I fix this?

3 Answers 3

1

It would be advisable to take a backup of your database before doing this.

Run the following SQL query to identify the duplicate entry in the eav_attribute_group table

SELECT * FROM `eav_attribute_group` WHERE `attribute_group_name` = 'General';

This will show you the existing entries with the attribute group name 'General' and their respective attribute set IDs.

Once you've identified the duplicate entry, you can delete it using the following SQL query:

DELETE FROM `eav_attribute_group` WHERE `attribute_group_name` = 'General' AND `attribute_set_id` = <attribute_set_id>;

now try to run

php bin/magento setup:upgrade 
0
0

Not sure about this one but I think the assignment of attributes to a group should happen only if the attribute is created and leave everything else as it was.
Try changing this

       foreach ($productAttributes as $attributeCode => $attributeData) {

            if (!$eavSetup->getAttributeId(Product::ENTITY, $attributeCode)) {
                $eavSetup->addAttribute(Product::ENTITY, $attributeCode, $attributeData);
            }
            // Assign attributes to default attribute set
            $eavSetup->addAttributeToGroup(
                $entityTypeId,
                $attributeSetId,
                $attributeData['group'],
                $attributeCode
            );
        }

to this

         foreach ($productAttributes as $attributeCode => $attributeData) {

            if (!$eavSetup->getAttributeId(Product::ENTITY, $attributeCode)) {
                $eavSetup->addAttribute(Product::ENTITY, $attributeCode, $attributeData);
            // Assign attributes to default attribute set
            $eavSetup->addAttributeToGroup(
                $entityTypeId,
                $attributeSetId,
                $attributeData['group'],
                $attributeCode
            );
            }
            
        }
0

Hi mate I had the same issue and I solved it with this patch.

--- Setup/MetaCatalogAttributes.php 2023-06-30 19:58:20 +++ Setup/MetaCatalogAttributes.php 2023-07-21 12:46:51 @@ -18,7 +18,7 @@ { return [ 'google_product_category' => [

  •            'group' => 'General',
    
  •            'group' => 'General Information',
               'type' => 'varchar',
               'label' => 'Google Product Category',
               'input' => 'select',
    

@@ -34,7 +34,7 @@ 'visible_on_front' => false ], 'send_to_facebook' => [

  •            'group' => 'General',
    
  •            'group' => 'General Information',
               'type' => 'int',
               'label' => 'Send to Facebook',
               'default' => 1,
    

Bassicaly check if the group "General" is the correct one in your project.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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