Magento Database – Find Entity ID and Attribute ID of an Attribute

attributesdatabase

We need to convert a dropdown attribute to multiselect

I found a way here :

If attribute_code : age ,
entity_type_id = 10 ,
store_id = 1

UPDATE eav_attribute SET
entity_type_id = '10',
attribute_model = NULL,
backend_model = 'eav/entity_attribute_backend_array',
backend_type = 'varchar',
backend_table = NULL,
frontend_model = NULL,
frontend_input = 'multiselect',
frontend_class = NULL
WHERE attribute_id = 'age';

Next, copy the attribute values from the old table to the new:

INSERT INTO catalog_product_entity_varchar ( 10, attribute_id, 1, entity_id, value)
SELECT entity_type_id, attribute_id, 1, entity_id, value
FROM catalog_product_entity_int
WHERE attribute_id = age;

Finally, remove the old values or they will conflict with the new setup (the old values will load, but Magento will save new values to the varchar table):

DELETE FROM catalog_product_entity_int
WHERE entity_type_id = 10 and attribute_id = age;

Credits :

http://swarminglabs.com/how-to-change-a-product-dropdown-attribute-to-a-multi-select/

but here i want to know how to find "attribute_id and entity_id" for an attribute. so i can replace those values in above queries

Best Answer

you can find the entity_type id like this.

SELECT 
    entity_type_id 
FROM 
    eav_entity_type
WHERE
    entity_type_code = 'catalog_product'

and the attribute id like this

SELECT 
    attribute_id
FROM 
    eav_attribute
WHERE 
    attribute_code = 'age' AND
    entity_type_id = (SELECT 
                          entity_type_id 
                      FROM 
                          eav_entity_type
                      WHERE
                          entity_type_code = 'catalog_product'
                      )

or simply

SELECT 
    attribute_id
FROM 
    eav_attribute
WHERE 
    attribute_code = 'age' AND
    entity_type_id = THE RESULT FROM THE FIRST QUERY
Related Topic