cancel
Showing results for 
Search instead for 
Did you mean: 

InstallData script never called even though no entry in setup_module

InstallData script never called even though no entry in setup_module

Hello I have created a module in accordance to the tutorial at Magento Docs

My InstallData class looks like this:

 

 <?php
    /**
     * Copyright © 2016 Magento. All rights reserved.
     * See COPYING.txt for license details.
     */
    
     namespace Learning\ClothingMaterial\Setup;
     
     use Magento\Framework\Setup\InstallDataInterface;
     use Magento\Framework\Setup\ModuleContextInterface;
     use Magento\Framework\Setup\ModuleDataSetupInterface;
     
     /**
     * @codeCoverageIgnore
     */
     class InstallData implements InstallDataInterface
     {
         /**
          * Eav setup factory
          * @var EavSetupFactory
          */
         private $eavSetupFactory;
     
         /**
          * Init
          * @param CategorySetupFactory $categorySetupFactory
          */
         public function __construct(\Magento\Eav\Setup\EavSetupFactory $eavSetupFactory)
         {
            $timestamp = time();
            $myfile = fopen("install_log.txt", "a") or die("Unable to open file!");
            fwrite($myfile, $timestamp . " - Install construct start\n");
            fclose($myfile);
             $this->eavSetupFactory = $eavSetupFactory;
         }
     
         /**
          * {@inheritdoc}
          * @SuppressWarnings(PHPMD.CyclomaticComplexity)
          * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
          * @SuppressWarnings(PHPMD.NPathComplexity)
          */
         public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
         {
            $timestamp = time();
            $myfile = fopen("install_log.txt", "a") or die("Unable to open file!");
            fwrite($myfile, $timestamp . " - Install start\n");
            fclose($myfile);
             $eavSetup = $this->eavSetupFactory->create();
             $eavSetup->addAttribute(
                 \Magento\Catalog\Model\Product::ENTITY,
                 'clothing_material',
                 [
                     'group' => 'General',
                     'type' => 'varchar',
                     'label' => 'Clothing Material',
                     'input' => 'select',
                     'source' => 'Learning\ClothingMaterial\Model\Attribute\Source\Material',
                     'frontend' => 'Learning\ClothingMaterial\Model\Attribute\Frontend\Material',
                     'backend' => 'Learning\ClothingMaterial\Model\Attribute\Backend\Material',
                     'required' => false,
                     'sort_order' => 50,
                     'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
                     'is_used_in_grid' => false,
                     'is_visible_in_grid' => false,
                     'is_filterable_in_grid' => false,
                     'visible' => true,
                     'is_html_allowed_on_front' => true,
                     'visible_on_front' => true
                 ]
             );
         }
     }



As you can see I added some write to file operations in order to check whether the class is actually called. The file never gets created. So the constructor and install method have never been called.

I already deleted the corresponding entry in the setup_module table and cleared caches, but it still dosen't get called when "php magento setup:upgrade" is executed.

What can be the reason?

2 REPLIES

Re: InstallData script never called even though no entry in setup_module

@Jens_Noma, have you create registration.php file in your module? if yes, Please check under database table setup_module if your entry is already exist remove from table and run php bin/magento setup:upgrade command.

 

Update:

could you show your registration.php and module.xml file?

If Issue Solved, Click Kudos/Accept As solutions.

Re: InstallData script never called even though no entry in setup_module

@Rakesh Jesadiya: Yes, I have a registration.php and I already checked and deleted the corresponding entry in setup_module. But the script is still not loaded after running "php magento setup:upgrade"