2

we missly deleted the attribute : "age" from live site.

attribute code : "age" attribute label : Age group

we assigned this attribute to thousands of products.

is there any option to get that attribute back in database?

we have a yesterday database backup.

is i have to export the eav_attribute table from yesterday database and import to the current database?....

for this to do, is i have to delete the eav_attribute table from current database?

or is there any option to export and import only particular attribute instead of "eav_attribute" table

2

Delete all records from current eav_attribute table and Export eav_attribute table from old database is not good idea.

eav_attribute table is master table for all magento eav attribute like eav_attribute_group,eav_attribute_label,eav_attribute_option,eav_attribute_option_value,eav_attribute_set etc.

As,you have delete all records and import all records that will created issue in import as primary key automatically increase.

Better idea to create same attribute at current system and export product/customer's related this attribute value in database.

  • i did't got this line : "export product/customer's related this attribute value in database. " – Baby in Magento Jan 4 '16 at 13:14
  • we already assigned thousands of products to that attribute. if we create new attribute again we have to allocate all thousand of products to that attribute. – Baby in Magento Jan 4 '16 at 13:15
  • hey,ur problem is solved or not? – Amit Bera Jan 6 '16 at 7:58
7

You don't need to delete the full eav_attribute table.
Just restore your backup in a different database.
Export your age attribute. You can use phpmyadmin, it's easier. You should get something like this:

INSERT INTO eav_attribute (attribute_id, ...) VALUES (99, ....);

99 is just a placeholder. The id can be different for you.
Run that query into your live database.
Then look in the table catalog_eav_attribute for the record with the same id as above (99 in my example). Export that row and import it in your live database.
If the attribute is not a dropdown attribute, just look in your backup for the attribute values from that attribute.
If the attribute type is int look in the table catalog_product_entity_int, if it's varchar look in catalog_product_entity_varchar and so on.
to get the values run this

SELECT * FROM {table} where attribue_id = 99;

Where {table} is the table described above and 99 is your actual attribute id.
Export these values and import them in your live database.
Then look in the table eav_attribute_group for records with attribute_id equal to your attribute id (99 in my example) and do the same. Export the rows from your backup and import them in your live db.
Then reindex everything.
If your attribute is a dropdown or multiselect you need to search for the options also and it's a bit more complicated.

  • INSERT INTO eav_attribute (attribute_id, ...) VALUES (99, ....); = > giving error = > #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '..) VALUES (99, ....)' at line – Baby in Magento Jan 4 '16 at 13:33
  • 2
    Did you take the query that I posted and ran it on your live db? That was just an example. You should get different values. Please backup your live db before trying anything else. – Marius Jan 4 '16 at 13:38
  • how to find the attribute id ? is i have to follow this : magento.stackexchange.com/questions/14855/… ? or is i have to place existed attribute code in the query you gave to me – Baby in Magento Jan 4 '16 at 13:52
  • SELECT * FROM eav_attribute where attribute_code = 'age'. This will get you the line you need from your backup. Then export this line, and import it in your live db. Just curious, are your even reading the answers or you're just copy-pasting queries hoping it will work? – Marius Jan 4 '16 at 13:54
  • 2
    Sorry. I quit. I have no other ideas. – Marius Jan 4 '16 at 14:38
2

three table you need to update according to your previous values

first

eav_attribute if you have backup of this table then execute the insert query.

second

eav_attribute_option add attribute option according to that attribute

third

eav_attribute_option_value add the options values.. find the option_id and insert those too..

after that you have to set the attribute to attribute set.

2

I think I am late but I face the same problem. I have deleted one of the attribute in our live site that is assigned to many products. It was a select attribute. What worked for me it was just adding that attribute in EAV_ATTRIBUTE table and all options and its value automatically comes without inserting it so I think Magento does not delete options and its values

I have run following SQL query in my PHP Myadmin

INSERT INTO `eav_attribute` (`attribute_id`, `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 (136, 4, 'Test', NULL, NULL, 'int', NULL, NULL, 'select', 'Test', NULL, 'eav/entity_attribute_source_table', 0, 1, '', 0, NULL);

Note: attribute_id and attribute_code can different so just edit the query accordingly.

  • Great solution buddy, Thanks for that..... – Baby in Magento Mar 9 '17 at 13:04

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.