I treid to create customer attribute programatically and now i want to update that the attribute with different label and type . I want to know in which table it will stored . I want to remove that attribute also.

public function install(ModuleDataSetupInterface $setup,ModuleContextInterface $context)

        $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
                'type'         => 'varchar',
                'label'        => 'Mobile',
                'input'        => 'integer',
                'required'     => true,
                'visible'      => true,
                'user_defined' => true,
                'position'     => 999,
                'system'       => 0,
        $eavSetup->updateAttribute('customer', 'phone_number', 'type', 'varchar');
        $attribute = $this->eavConfig->getAttribute(Customer::ENTITY, 'phone_number');     
            ['adminhtml_customer', 'customer_account_create']



3 Answers 3


The attribute itself stored eav_attribute table. please check with following SQL in mysql:

SELECT * FROM `eav_attribute` where attribute_code='phone_number';

And the values are store in customer_entity_varchar table.

SELECT * FROM `customer_entity_varchar` where attribute_id=ID_OF_ATTRIBUTE_FROM_EAV_TABLE 

If you want to upadte your Attribute then you need to add upgrade script. You cannot simply add in install script. Here is how upgrade script look like in app/code/VENDOR/MODULE/Setup/UpgradeData.php file:

namespace VENDOR\MODULE\Setup;

use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Eav\Setup\EavSetupFactory;

class UpgradeData implements UpgradeDataInterface

    public function __construct(EavSetupFactory $eavSetupFactory)
        $this->eavSetupFactory = $eavSetupFactory;

    public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)

        //handle all possible upgrade versions

        if (!$context->getVersion()) {
        if (version_compare($context->getVersion(), '2.1.0') < 0) { //VERSION OF YOUR MODULE in module.xml
            $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
            $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
            /** @var \Magento\Eav\Model\ResourceModel\Entity\Attribute $attribute */
            $attribute = $objectManager->create('\Magento\Eav\Model\ResourceModel\Entity\Attribute');
            $attributeId = $attribute->getIdByCode('customer','phone_number');

  • It returns empty set Aug 9, 2018 at 11:31
  • 1
    Then your attributes was not created at all. If it has been created then it should be seen in eav table Aug 9, 2018 at 11:35
  • can you help me to how to do that ??? Aug 9, 2018 at 11:37

The customer attribute you have created is stored in the table customer_entity_varchar as you had declared in your code with the "type" property. Another reference to that attribute is going to be stored at customer_entity with the entity_id as a reference.

  • select * from customer_entity_varchar ; returns empty set Aug 9, 2018 at 11:41

the only thing that worked for me was to use the getConnection function in an upgrade data script like this:


if (version_compare($context->getVersion(), '2.1.8', '<'))

$attribute_id = $this->_eavAttribute->getIdByCode('customer', 'attribute_code');
['is_required' => false], 'attribute_id=' . $attribute_id);


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.