Magento2 – Adding a Custom Customer Attribute

customercustomer-attributecustomer-gridmagento2

I have a system where custom attributes were added in customer_grid_flat table.

That way, those attributes appear in Account Information tab of customer administration pages. However, when I try to save a data in them, data are not actually saved.

Customer attributes are note created in customer_entity table. Could that be the reason of why the attribute data are not saved? When creating custom attributes, should they be created in customer_entity table only? What is the goal of customer_grid_flat table?

Thanks

Best Answer

You will have to create custom attribute in a standard way for customer entity. If your custom attribute's data type is static then it will be visible in 'customer_entity" table otherwise it will visible in respective customer entity data type table (e.g. customer_entity_int for int data type).

The 'customer_grid_flat' table is an additional table in which you can add your custom attribute field to display it on admin customer grid with search and filter options.

I hope this help you to understand the core concept of custom attribute of customer entity. Once you follow this your custom attribute's value will start getting saved in the respective database table as explained.

Related Topic