1

I am trying to create a new table via my module Ved_Mymodule

This module is active and when I change its setup_version in module.xml file then it is reflecting in setup_module table in the database.

\app\code\Ved\Mymodule\Setup\UpdateSchema.php

<?php

namespace Ved\Mymodule\Setup;

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

class UpgradeSchema implements UpgradeSchemaInterface
{
    public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        $installer = $setup;
    $installer->startSetup();

    // Get emqube_mymodule table
    $tableName = $installer->getTable('ved_mymodule');
    // Check if the table already exists
    if ($installer->getConnection()->isTableExists($tableName) != true) {
        // Create emqube_mymodule table
        $table = $installer->getConnection()
            ->newTable($tableName)
            ->addColumn(
                'id',
                Table::TYPE_INTEGER,
                null,
                [
                    'identity' => true,
                    'unsigned' => true,
                    'nullable' => false,
                    'primary' => true
                ],
                'ID'
            )
            ->addColumn(
                'title',
                Table::TYPE_TEXT,
                null,
                ['nullable' => false, 'default' => ''],
                'Title'
            )
            ->addColumn(
                'summary',
                Table::TYPE_TEXT,
                null,
                ['nullable' => false, 'default' => ''],
                'Summary'
            )
            ->addColumn(
                'description',
                Table::TYPE_TEXT,
                null,
                ['nullable' => false, 'default' => ''],
                'Description'
            )
            ->addColumn(
                'created_at',
                Table::TYPE_DATETIME,
                null,
                ['nullable' => false],
                'Created At'
            )
            ->addColumn(
                'status',
                Table::TYPE_SMALLINT,
                null,
                ['nullable' => false, 'default' => '0'],
                'Status'
            )
            ->setComment('News Table')
            ->setOption('type', 'InnoDB')
            ->setOption('charset', 'utf8');
        $installer->getConnection()->createTable($table);

        }

        //if (version_compare($context->getVersion(), '1.0.3') < 0) {
            //code to upgrade to 1.0.3
        //}

        $installer->endSetup();
    }
}

Then I have run:

php bin/magento setup:db-schema:upgrade

php bin/magento setup:upgrade

But that table is not creating in the database.

1 Answer 1

3

Try below steps.

  1. Go to current Magento instances Database and remove the record from setup_module with module = 'Ved_Mymodule'.
  2. Remove the cache.
  3. Run the command php bin/magento setup:upgrade.

Hope this helps.

1
  • Thank you so much.. :) It worked. But I did not get whether it was a cache issue or something else.
    – vedu
    Commented Jul 26, 2016 at 7:30

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.