I just updated from CE 2.1.2 to CE 2.1.3
Upon running setup:upgrade, I received an error message on the command line:
Notice: Undefined index: attribute_id in /var/www/magento2/public_html/vendor/magento/module-catalog/Setup/UpgradeData.php on line 375.
This line of code occurs in a loop that attempts to update several attributes to a global scope. The attributes to be updated are: price, cost, and special_price.
The problem is that cost is a user-defined attribute, and I deleted it a long time ago. The loop should ensure that the attribute exists before attempting to update it.
The information I've provided should be more than enough to recognize the issue without even testing it:
'cost' is a user-defined attribute and can be deleted at will.
'cost' has a hardcoded update in an UpgradeData.php file.
Please don't ask me to edit this to conform to Magento's bug report conventions. I spent enough time getting this upgrade to work and tracking this bug down. I will not respond and this easy fix will be closed after 2 weeks due to no replies.
Internal jira ticket - MAGETWO-62266 created.
I am having the exact same problem...
[Exception]
Notice: Undefined index: attribute_id in XXXXX/vendor/magento/module-catalog/Setup/UpgradeData.php on
line 375
@AirmanAJK can you tell me how I can get around this for now? thanks!
@AirmanAJK I just removed cost in the array on line 371 of UpgradeData.php and ran the upgrade again and was able to get by for now... is this the same as what you did? will this have any consequence?
@jvreeken That's exactly right. This will not have any consequences assuming you deleted the cost attribute (which I'm sure you did since it crashed in the first place). I'm not aware of any other part of Magento that requires a cost attribute to function.
Hey ,
I hope that correct solution will be that we can create the old attribute "cost" in the table eav_attribute by using the 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);
Then pls check the attribute_id of the "cost" and use it for creating another table entry in "catalog_eav_attribute" by using the query
INSERT INTO catalog_eav_attribute (attribute_id, frontend_input_renderer, is_global, is_visible, is_searchable, is_filterable, is_comparable, is_visible_on_front, is_html_allowed_on_front, is_used_for_price_rules, is_filterable_in_search, used_in_product_listing, used_for_sort_by, apply_to, is_visible_in_advanced_search, position, is_wysiwyg_enabled, is_used_for_promo_rules, is_required_in_admin_store, is_used_in_grid, is_visible_in_grid, is_filterable_in_grid, search_weight, additional_data) VALUES
(81, NULL, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'simple,virtual,downloadable', 0, 0, 0, 0, 0, 1, 0, 1, 1, NULL);
pls use the attribute_id of cost instead of 81 .
the run the setup upgrade hope it will work fine.
if you have different deployment stage use install script for running the above query
Thanks
This issue was fixed in develop branch,
Internal ticket for ver. 2.1 - MAGETWO-62266
@AirmanAJK, thank you for your report.
The issue is already fixed in 2.2.0
Most helpful comment
Hey ,
I hope that correct solution will be that we can create the old attribute "cost" in the table eav_attribute by using the 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);
Then pls check the attribute_id of the "cost" and use it for creating another table entry in "catalog_eav_attribute" by using the query
INSERT INTO
catalog_eav_attribute(attribute_id,frontend_input_renderer,is_global,is_visible,is_searchable,is_filterable,is_comparable,is_visible_on_front,is_html_allowed_on_front,is_used_for_price_rules,is_filterable_in_search,used_in_product_listing,used_for_sort_by,apply_to,is_visible_in_advanced_search,position,is_wysiwyg_enabled,is_used_for_promo_rules,is_required_in_admin_store,is_used_in_grid,is_visible_in_grid,is_filterable_in_grid,search_weight,additional_data) VALUES(81, NULL, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'simple,virtual,downloadable', 0, 0, 0, 0, 0, 1, 0, 1, 1, NULL);
pls use the attribute_id of cost instead of 81 .
the run the setup upgrade hope it will work fine.
if you have different deployment stage use install script for running the above query
Thanks