Magento – Error with Magento\Eav\Model\Entity\Attribute how to fix

eaveav-attributeserrormagento2

I have this error,

1 exception(s):
Exception #0 (Exception): Item (Magento\Eav\Model\Entity\Attribute) with the same ID "87" already exists.

it seems to me that there must be a duplicate row ?

But what Table as I cant find one.

Thanks.

Best Answer

Some migration or system that populates the database which caused the duplication of IDs. Magento core predicts a data created by its self, so this kind of error could be solved without stopping the system but it was not implemented yet (e.g. Github issue in the reference session).

Solution

  • Recreate the attribute or remove the attribute
  • Change the attribute ID through the database
  • Create a core patch to skip attribute with error to not show or show it unfilled in the product page to edit as below (creating a module):
// file: vendor/magento/framework/Data/Collection.php

    public function addItem(\Magento\Framework\DataObject $item)
    {
        $itemId = $this->_getItemId($item);

        if ($itemId !== null) {
//            if (isset($this->_items[$itemId])) {
//                throw new \Exception(
//                    'Item (' . get_class($item) . ') with the same ID "' . $item->getId() . '" already exists.'
//                );
//            }
            $this->_items[$itemId] = $item;
        } else {
            $this->_addItem($item);
        }
        return $this;
    }
Related Topic