What if I change the EAV attribute backend type in Magento?

The question is raised because in my catalog_category, I have a user attribute originally 255 length varchar. Now I am told by users it was not long enough for block text. I want to change it to text type in mysql to solve the problem.

I know EAV attributes use different tables for different type. My worry is moving attribute value from varchar table to text table when changing the EAV attribute backend type. Anyway, I have to try before I know. Here is my steps:

  1. go to table magento_eav_attribute, find the attribute, change backend_type from varchar to text
  2. (what’s next?) I am about to change something else, but surprisingly, nothing else! All done after step 1.

I do not need to move old values from magento_catalog_category_entity_varchar to magento_catalog_category_entity_text. After change attribute’s backend_type, Magento can still read existing value from magento_catalog_category_entity_varchar, but if I save the category, the value will save to magento_catalog_category_entity_text. Old value is not deleted from magento_catalog_category_entity_varchar, but it does no harm.

I am curious at how Magento did it – Does Magento go through 5 tables (datetime, decimal, int, text, varchar) to get a value? Or Magento cache attributes’ backend type (so even I make changes in magento_eav_attribute, Magento still have records of old type)?

2 comments

  1. This is not correct for magento CE 1.5.1.
    I have encountered bug that was involving this.

    Scenario:
    We had programmatically created product attribute with backend_type int and frontend type text.
    Then our staff went to admin site and saved (edited) this attribute and magento did silently change backend_type to varchar.
    Problem encountered when we tried to change existing product values and it didn’t work.
    After long debugging we have found out that catalog_product_entity_int table was storing values and magento was writing to them there but displaying from catalog_product_entity_varchar.

    Conclusion:
    After changing attribute backend type you should always handle yourself copying existing data!

Leave a comment

Your email address will not be published. Required fields are marked *