0

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();
  • Have you created any install data script in any module? – Charul Tyagi Aug 16 '18 at 11:14
  • Yes, that's what I meant by 'added some install data to my module'. I will add it to the question. – Ynhockey Aug 16 '18 at 11:30
  • have you check your module version is going into setup_module table? – Charul Tyagi Aug 16 '18 at 11:36
  • It's not going up, I thought it didn't matter for install (only for upgrade), but might be wrong. In any case, this is part of the question, is it possible to force-run the install script without changing the version? – Ynhockey Aug 16 '18 at 11:37
5

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.

1

Thanks to @Dani I was able to resolve this. I had a module install that went bad and I was getting:

Table 'magento.mgz_ninjamenus_menu' doesn't exist

I use docker and so here is the complete list of commands I used to help this (might help a Magento noob):

#view list docker container names
docker ps --format "{{.Names}}"

#connect to the docker instance
docker exec -it name_of_mysql_container bash

mysql -umagento -pmagento magento

use magento;
select * from setup_module;
#find the name of the module in the displayed list

delete from setup_module where module = 'module_name_from_the_query_above';

#you should see something like:
#   Query OK, 1 row affected (0.00 sec)
exit
exit

#now run your own flush commands including:
#  bin/magento setup:upgrade

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.