Magento2 not executing InstallSchema.php or UpgradeSchema.php
-
13-04-2021 - |
Question
I've created a custom module, and I see the row in the setup_module
table. When I change my version and run magento setup:upgrade
, the version number updates as well. However, the table I defined is not being created. I also see the new module enabled in app/etc/config.php
I tried installing a module written by Magento, but I still see the same behavior - row is in setup_module
but table does not exist.
I tried deleting the row from setup_module
table and rerun magento setup:upgrade
to execute InstallSchema.php
, but the database tables aren't created even though the row is created setup_module
again.
I also tried incrementing the version number and try UpgradeSchema.php, but it doesn't execute even though row in setup_module
is updated.
I introduced errors in both InstallSchema.php
and UpgradeSchema.php
, but magento setup:upgrade
doesn't does not output the error messages.
I also tried recreating the installation, and ensuring the file permissions were correct (owned by magento:www-data
). Any other ideas?
I'm using v2.0.7 CE provided by DigitalOcean.
<?php
namespace Test\Project\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();
// Get tables
$tableName = $installer->getTable('test_module');
// Create 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'
)
->setOption('type', 'InnoDB')
->setOption('charset', 'utf8');
$installer->getConnection()->createTable($table);
$installer->endSetup();
} // close function install()
}
Solution 2
I resolved this by disabling all the caches via the admin and re-installing the module.
OTHER TIPS
I have tried the following thats works for me. please check.
delete from setup_module where module ='module_name';
sudo bin/magento setup:upgrade
sudo bin/magento setup:di:compile
sudo bin/magento cache:clean
In my case the package name
was wrong. After replacing by right package name
issue is fixed.
namespace Package_Name\Module_Name\Setup;