Magento 2 – How to Force-Run Module Install Script

install-scriptinstalldatamagento2

I have added some install data to my module (EAV attributes), and it doesn't look like it's working. However, I don't seem to get any relevant errors in the logs, and am a bit lost on whether the install script ever ran in the first place. I tried two ways to run it:

  • Disable/enable module
  • Running setup:upgrade

Is there a way to force-run just my install script? If not, does setup:upgrade always run it, and if so, which log should I be looking at?

Edit: Here is the relevant part of the install data script:

$customerSetup->addAttribute(Customer::ENTITY, 'some_action_timestamp', [
        'type' => 'int',
        'label' => 'Some action timestamp',
        'input' => 'text',
        'required' => false,
        'visible' => false,
        'user_defined' => true,
        'sort_order' => 1000,
        'position' => 1000,
        'system' => 0,
    ]);

    $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'some_action_timestamp')
        ->addData([
            'attribute_set_id' => $attributeSetId,
            'attribute_group_id' => $attributeGroupId,
            'used_in_forms' => ['adminhtml_customer'],
        ]);

    $attribute->save();

Best Answer

If you are trying to run installation scripts for a "local" module (not installed with composer) and the module is already installed, you should:

  • Remove module installation registry from database, in the setup_module table.
  • Re-run bin/magento setup:upgrade

This will execute installation scripts as if the module wasn't previously installed.

Related Topic