1

I've the following setup:

Company/Custom/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="Custom" setup_version="1.0.6"></module>
</config>

Company/Custom/Setup/UpgradeSchema.php:

<?php

namespace Company\Custom\Setup;

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

class InstallSchema implements InstallSchemaInterface
{

/**
 * {@inheritdoc}
 * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
 */
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
{   
    $installer = $setup;

    $installer->startSetup();

    $eavTable = $installer->getTable('customer_entity');

    $columns = [
        'custom' => [
            'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
            'length' => '1',
            'nullable' => true,
            'comment' => 11,
        ],
    ];

    $connection = $installer->getConnection();
    foreach ($columns as $name => $definition) {
        $connection->addColumn($eavTable, $name, $definition);
    }

    $installer->endSetup();
}

}

I've removed the module from the setup_module table and run the upgrade commands. Also, the module is appears in the dashboard and its enabled.

The problem is that table is not created in database after I run the scripts but if I put errors in the php file, the upgrade scripts run without error.

As you can see I incremented the module version in the module.xml.

Thanks.

2
  • You've put your code in upgrade schema, put your code into install schema to make it work Commented Sep 15, 2017 at 10:11
  • Please look at Magento\Cms\Setup\InstallSchema and do the same. And you forget about $installer->getConnection()->createTable($table); Commented Sep 15, 2017 at 10:12

2 Answers 2

1

Your file name is UpgradeSchema.php but you have used the InstallSchema code. Change your file name to InstallSchema.php and code should be like this:

namespace Company\Custom\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)
    {
        $installer = $setup;
        $installer->startSetup();


        $installer->endSetup();
    }
}

Yes if you want to make change in Existing table then it should be in UpgradeSchema file. But main function name should be upgrade instead of install like below code:

namespace Company\Custom\Setup;

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

/**
 * @codeCoverageIgnore
 */
class UpgradeSchema implements UpgradeSchemaInterface
{
    /**
     * {@inheritdoc}
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
     */
    public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        $installer = $setup;
        $installer->startSetup();

        $setup->endSetup();
    }
}
0

I had the same issue, I was not getting any errors and nothing has happened. I was using the same code as well. I tried the solution above and more suggestions in other post and nothing fixed my issue.

I realized that my Setup folder was one level "above" the expected level.

Expected directory level

-Mastering->
--SampleModule->
---Setup->

I had my "Setup" folder at the same level as my module.

-Mastering->
--SampleModule->
--Setup->

I moved my "Setup" folder to the right level and everything worked as a charm!

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.