5

My magento current version is 2.1.2 and upgraded with Composer by following command:

composer require magento/product-community-edition 2.1.3 --no-update
composer update
php bin/magento cache:clean
php bin/magento cache:flush
php bin/magento setup:upgrade

I'm getting following error while run command php bin/magento setup:upgrade

[Exception] Notice: Undefined index: attribute_id in vendor\magento\module-catalog\Setup\UpgradeData. php on line 375

Please help me for solve this error.

1 Answer 1

3

Your error comes from this method:

/**
 * @param \Magento\Catalog\Setup\CategorySetup $categorySetup
 * @return void
 */
private function changePriceAttributeDefaultScope($categorySetup)
{
    $entityTypeId = $categorySetup->getEntityTypeId(\Magento\Catalog\Model\Product::ENTITY);
    foreach (['price', 'cost', 'special_price'] as $attributeCode) {
        $attribute = $categorySetup->getAttribute($entityTypeId, $attributeCode);
        $categorySetup->updateAttribute(
            $entityTypeId,
/*375*/     $attribute['attribute_id'],
            'is_global',
            \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL
        );

    }
}

The feasible issue is the absence of the attribute from the list ['price', 'cost', 'special_price'] in your system. Maybe you’ve deleted one of them?

You can find all of them in the table eav_attribute usin the query:

SELECT * FROM `eav_attribute` WHERE `attribute_code` IN ('price', 'cost', 'special_price')

You should see something similar to this:

query result

If you want to restore your cost attribute use this query:

INSERT INTO eav_attribute (entity_type_id, attribute_code, attribute_model, backend_model, backend_type, backend_table, frontend_model, frontend_input, frontend_label, frontend_class, source_model, is_required, is_user_defined, default_value, is_unique, note) VALUES (4, 'cost', null, 'Magento\\Catalog\\Model\\Product\\Attribute\\Backend\\Price', 'decimal', null, null, 'price', 'Cost', null, null, 0, 1, null, 0, null);
5
  • hey,thank you so much actually at my side "cost" attribute not exist so getting this error.I solved this error by adding if condition above $categorySetup->updateAttribute. Dec 20, 2016 at 12:24
  • 1
    @SnehaPanchal I was glad to help you. I recommend you to restore a system attribute to prevent other errors later. Dec 20, 2016 at 12:28
  • But how can i restore? Dec 20, 2016 at 12:36
  • @SnehaPanchal I added the query to my answer, please try it. Dec 20, 2016 at 12:57
  • 2
    You need to make one more insert statement. See this answer - github.com/magento/magento2/issues/7804#issuecomment-268457430
    – Arvind07
    Feb 19, 2017 at 6:07

Your Answer

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

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