Why ENUM is not supported in Magento 2

Since initials days of Mysql when ENUM data type was released, it was considered as a bad idea and using enum as a data type was a bad practice. Reasons why ENUM should not be used anywhere.

ENUM violates basic rules of data normalisation.

If you have too many entries in table and you want to update list of possible ENUM values, it will be a very expensive operation, because it leads to table rebuild with lock during this process, due to locking of table entire application will come to standstill.

ENUM is very limited, you can’t add additional attributes for your ENUM entities. suppose you have a attribute called “currency”, using ENUM only 1 value is possible [“INR”,”USD”,”GBP”] what if you want to add country name to it? it is not possible!

ENUM entity couldn’t be re-used in another table if needed. So, developer will need to duplicate ENUM declaration. Which is incorrect as any other code duplication.

A better option is to use reference table to store all possible enumerations with proper data type. just like shown in image below.

You can know more pain areas of using ENUM in table at : http://komlenic.com/244/8-reasons-why-mysqls-enum-data-type-is-evil/



Working in software industry since last 10+ years, have done feature rich web apps & automations and helped organizations to save cost.

Leave a reply:

Your email address will not be published.