0

I am trying to create installation script that make a record to cms_page table.

So i created the next directory /app/code/Magento/Page/

Here is my /etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Page" setup_version="1.0.0" />
</config>

And registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
        \Magento\Framework\Component\ComponentRegistrar::MODULE,
        'PageEdu2',
        __DIR__
    );

Here is InstallData.php

<?php

namespace Magento\Page\Setup;

use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

class InstallData implements InstallDataInterface
{
    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
        $setup->getConnection()->query("INSERT INTO inviqa_example SET name = 'Test 1'");
    }
}

Problem is that after installing i have no inviqa_example table in mysql.

After command php -f bin/magento setup:upgrade i have long module list. Last rows are next: Module 'Page': Please re-run Magento compile command

3

your class inserting data to the table, you need class wich create schema, call InstallSchema

for example

 namespace COmpany\youModule\Setup;

    use Magento\Framework\Setup\InstallSchemaInterface;
    use Magento\Framework\Setup\ModuleContextInterface;
    use Magento\Framework\Setup\SchemaSetupInterface;

    /**
     * @codeCoverageIgnore
     */
    class InstallSchema implements InstallSchemaInterface
    {
        /**
         * {@inheritdoc}
         * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
         */
        public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
        {


        $installer = $setup;
            $installer->startSetup();

            /**
             * Create table 'customer_entity'
             */
            $table = $installer->getConnection()->newTable(
                $installer->getTable('inviqa_example')
            )->addColumn(
                'id',
                \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                null,
                ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
                'Entity Id'
            )->addColumn(
                'somecolumn',
                \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                null,
                ['nullable' => false],
                'api Id'
            )
               ->setComment(
            'comment'
        );
        $installer->getConnection()->createTable($table);
        $installer->endSetup();
    }
  }

or look for the same file in magento core modules

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.