2

I had created a sample module when I tried to create table I knew I have to delete the entry from my setup_module table or else the install schema wont run so.

DELETE from setup_module where module='Mastering_SampleModule'

After that I performed sudo bin/magento setup:upgrade;

Everthing runs fine, the module is being created again in the setup_module table as I check from

select * from setup_module WHERE module= 'Mastering_SampleModule'

but the table is not being created .

on trying to introduce error in installschema class and then running sudo bin/magento setup:upgrade the error is shown in the console according to error introduced and it is irrelevant. But table is not being created as expected if I run

sudo bin/magento setup:upgrade; command without any errors.

<?php

namespace Mastering\SampleModule\Setup ;

use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\DB\Ddl\Table;

class InstallSchema implements InstallSchemaInterface
{

        public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
        {
            $setup->startSetup();

            $table = $setup->getConnection()
                ->newTable($setup->getTable('mastering_sample_item)'))
                ->addColumn(
                    'id',
                    Table::TYPE_INTEGER,
                    null,
                    ['identity'=>true,'nullable'=>false,'primary'=>true],
                    'Table Id'
                )->addColumn(
                    'name',
                    Table::TYPE_TEXT,
                    255,
                    ['nullable'=>false],
                    'Table Name'

                )->addIndex(
                    $setup->getIdxName('mastering_sample_item',['name']),
                    ['name']

                )->setComment(
                    'Sample Items'
                );

            $setup->getConnection()->createTable($table);
            $setup->endSetup();
        } 
    }

I think there is any error in my install method , can someone tell me how to debug installschema and upgrade schema classes?

3
  • are you creating a new module or upgrading ? Oct 25, 2017 at 6:05
  • i am creating a new module and the row has been inserted in the setup_module table before , i just want to create a simple table . i need to run install schema again. Oct 25, 2017 at 6:11
  • Please check my ans for more information Oct 25, 2017 at 6:13

1 Answer 1

0

Please add below code in you InstallSchema.php

<?php


namespace Mastering\SampleModule\Setup;

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

class InstallSchema implements InstallSchemaInterface
{

    /**
     * {@inheritdoc}
     */
    public function install(
        SchemaSetupInterface $setup,
        ModuleContextInterface $context
    ) {
        $installer = $setup;
        $installer->startSetup();

        $table_mastering_samplemodule_sample_item = $setup->getConnection()->newTable($setup->getTable('mastering_samplemodule_sample_item'));


        $table_mastering_samplemodule_sample_item->addColumn(
            'sample_item_id',
            \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
            null,
            array('identity' => true,'nullable' => false,'primary' => true,'unsigned' => true,),
            'Entity ID'
        );



        $table_mastering_samplemodule_sample_item->addColumn(
            'item1',
            \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
            null,
            [],
            'item1'
        );



        $table_mastering_samplemodule_sample_item->addColumn(
            'item2',
            \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
            null,
            [],
            'item2'
        );


        $setup->getConnection()->createTable($table_mastering_samplemodule_sample_item);

        $setup->endSetup();
    }
}

I have created sample module for you please get it from below url

https://mage2gen.com/download/ffe0dd25-4ac3-4b4f-a797-7fdc8cc1b3f8.tar

6
  • used your installschema.php but still nothing , the row in the setup module is being created as before without creating the table select * from mastering_samplemodule_sample_item shows that the table doesn't exist; Oct 25, 2017 at 6:44
  • I have tried in my local and it is working fine for me Oct 25, 2017 at 6:59
  • so i guess the problem is not in the installSchema.php file , Could you suggest any way how to debug the module ? i am clueless here what to do as everything seems working fine , thanks . Oct 25, 2017 at 7:17
  • please get module link from my ans, I have created it for you Oct 25, 2017 at 7:25
  • 1
    thanks its working great , could you have a look at my module and guide me what i am doing wrong , its just a basic module we.tl/PipCUeaNzA Oct 26, 2017 at 5:17

Your Answer

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

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