0

I am practicing with the development of mageplaza modules. following the steps of the blog, but I don't know if my InstallData.php is badly created, but nothing is loaded to the database. I have the module created on github https://github.com/GNUXDAR/magento2_code/tree/development

<?php
namespace Actecnology\HellorWorld\Setup;

use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

class InstallData implements InstallDataInterface
{
    private $eavSetupFactory;

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

    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
        /**
           * Install messages
           */
          $data = [
            'name'         => "Bienvenidos al mundo del desarrollo de modulos de Magento2",
            'url_key'      => '/magento-2-module-development/wellcome.html',
            'post_content' => "En este articulo de prueba, le damos la bienvenida al desarrollo de modulos e integracion de magento, como sabemos magento2 es un sistema modular, en el cual desarrollaremos modulos necesarios para nuestro modelo de negocio.",
            'tags'         => 'magento 2,development',
            'featured_image'=> 'https://arturocabrera.com/img/slides/1.webp',
            'author'        =>  "@gnuxdar",
            'status'       => 1
        ];
        foreach ($data as $bind) {
            $setup->getConnection()
              ->insertForce($setup->getTable('actecnology_helloworld_post'), $bind);
        }
    }
}

with DataPatches show that message:

Cache types config flushed successfully
Cache cleared successfully
File system cleanup:
/var/www/html/act_magento/generated/code/Composer
/var/www/html/act_magento/generated/code/Dotdigitalgroup
/var/www/html/act_magento/generated/code/Magento
/var/www/html/act_magento/generated/code/PayPal
/var/www/html/act_magento/generated/code/Psr
/var/www/html/act_magento/generated/code/Symfony
/var/www/html/act_magento/generated/code/Vertex
/var/www/html/act_magento/generated/code/Yotpo
The directory '/var/www/html/act_magento/generated/metadata/' doesn't exist - skipping cleanup
Updating modules:
Cache cleared successfully
Schema creation/updates:
Primary db_schema file doesn`t exists

1 Answer 1

0

The InstalData approach is not a prefered way to modify data in 2022.

I'd recommend checking out the current approach with Data Patches. Check DevDocs at DataPatches page for more info.

Anyway, about your question. InstallData is only triggered when you first install the module. Workaround to make Magento process InstallData is to delete the record with your module's name from the database table - setup_data && bin/magento set:up

2
  • ohh, thank you very much. i delete the colum in the table setup_data and run setup:upgrade but not install the data in the table. :( Commented Apr 17, 2022 at 1:09
  • with Daa Patches show that message: Commented Apr 29, 2022 at 2:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.