skip to Main Content

I have created a file setup/installdata.php:

    use MagentoEavSetupEavSetup;
    use MagentoEavSetupEavSetupFactory;
    use MagentoFrameworkSetupInstallDataInterface;
    use MagentoFrameworkSetupModuleContextInterface;
    use MagentoFrameworkSetupModuleDataSetupInterface;

    class InstallData implements InstallDataInterface
    {
        private $eavSetupFactory;

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

        public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
        {
            $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
            $eavSetup->addAttribute(
                MagentoCatalogModelProduct::ENTITY,
                'name',
                [
                    'type' => 'int',
                    'backend' => '',
                    'frontend' => '',
                    'label' => 'attrlabel',
                    'input' => 'select',
                    'class' => '',
                    'source' => 'abModelAttributeSourcem',
                    'global' => MagentoEavModelEntityAttributeScopedAttributeInterface::SCOPE_GLOBAL,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'default' => '',
                    'searchable' => false,
                    'filterable' => false,
                    'comparable' => false,
                    'visible_on_front' => false,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'apply_to' => '',
                    'attribute_set' => 'Default',
                ]
            );
        }
    }

Then, in etc/module.xml, I have:

    <module name="Conlabz_IdentityCheck" setup_version="1.0.0" />

But I still don’t see the attribute created.

I also tried the following:

In the Magento root folder, I run the following commands:

    php bin/magento module:disable
    php bin/magento module:enable
    php bin/magento setup:upgrade
    php bin/magento cache:flush

All succeed without an error, but as I said, it doesn’t work.

What am I doing wrong?

2

Answers


  1. Check your filename setup/installData.php.

    “D” should be capital.

    Then search table “setup_module” in your magento2 database and delete entry for “Conlabz_IdentityCheck”.

    Then run following command :

    php bin/magento setup:upgrade

    php bin/magento setup:static-content:deploy -f

    Login or Signup to reply.
    1. First, the file and folder name should be Setup/InstallData.php
    2. In your InstallData.php file, you have to add this code at the first line:

      namespace ConlabzIdentityCheckSetup;

    Then just run the CLI commands.

    However, if you still facing issues then for reference you can checkout this guide on Magento Attributes.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search