While developing a new extension, I'm trying to update two tables at installation time by using Setup\InstallSchema.php
. The tables are "admin_user" and "customer_entity", and I basically need the same fields for both of them.
The InstallSchema.php
is triggered, but the tables don't get updated.
Please see the code & info below:
namespace Vendor\ModuleName\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
{
protected $installer;
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$this->installer = $setup;
$this->installer->startSetup();
$this->addUsersFields('admin_user');
$this->addUsersFields('customer_entity');
$this->installer->endSetup();
}
protected function addUsersFields($table)
{
$table = $this->installer->getTable($table);
$this->installer->getConnection()->addColumn(
$table,
'field1',
[
'type' => Table::TYPE_TEXT,
'nullable' => false,
'default' => 'field1Default',
'length' => '45',
'comment' => 'comment'
]
);
$this->installer->getConnection()->addColumn(
$table,
'field2',
[
'type' => Table::TYPE_TEXT,
'nullable' => false,
'default' => 'field2Default',
'length' => '45',
'comment' => 'comment'
]
);
}
}
EDITED: updated fields name correctly : field1 and field2
Using Magento 2.2.2 on AWS, from an AWS AMI. Developer mode enabled.
I'm running :
php bin/magento module:enable ModuleName
(works fine, tells me that has enabled the module)php bin/magento setup:upgrade
(works fine, I can see the module in the output)php bin/magento setup:di:compile
(works fine)
I've :
- made sure the
InstallSchema.php
is included each time by deleting the module entry from "setup_module" table; - tested that it's
triggered by deliberately deleting an ";" from a line, and within
php bin/magento setup:di:compile
it shows an error message and the process is stopped.
So basically I'm 100% sure the InstallSchema.php
is triggered.
THE PROBLEM is that the tables don't get updated, nor do I get any error message. Neither anything worth mentioned in exception.log, system.log or /var/log/apache2/error.log.
Any way to debug this?