I have InstallSchema.php as follows:
<?php
namespace Namespace\Module\Setup;
use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;
class InstallSchema implements InstallSchemaInterface
{
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
$table = $setup->getConnection()->newTable(
$setup->getTable('custom_table')
)->addColumn(
'custom_id',
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
null,
['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
'Custom Id'
)->addColumn(
'name',
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
255,
[],
'Custom Name'
)->setComment(
'Custom Table'
);
$setup->getConnection()->createTable($table);
$setup->endSetup();
}
}
InstallData.php as follows:
<?php
namespace Namespace\Module\Setup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
class InstallData implements InstallDataInterface
{
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
$tableName = $setup->getTable('custom_table');
$data = [
[
'name' => 'Content of the first post.',
],
[
'name' => 'Content of the second post.',
],
];
$setup
->getConnection()
->insertMultiple($tableName, $data);
$setup->endSetup();
}
}
I have executed php bin\magento setup:upgrade
at time of installing.
What I found was Table with defined Schema was created but no data was inserted.
Please help what I am missing here.
setup_module
table and re run the commandssetup:upgrade
.