I have used setup to create table but script is not creating the table. I have also removed the entry from setup_module table but still, it didn’t work. Ive tried migration to declarative schema using bin/magento setup:install --convert-old-scripts=1
since its a Magento 2.3
installation, but the original script needs to work first.
magento-path/app/code/Folder/CustomModule/Setup/InstallSchema.php
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace FolderCustomModuleSetup;
use MagentoFrameworkSetupInstallSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
/**
* @codeCoverageIgnore
*/
class InstallSchema implements InstallSchemaInterface
{
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
/**
* Create table 'shop_ocxe'
*/
$setup->startSetup();
$table = $setup->getConnection()
->newTable($setup->getTable('shop_ocxe'))
->addColumn(
'id',
MagentoFrameworkDBDdlTable::TYPE_SMALLINT,
null,
['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
'Shop ID'
)
->addColumn(
'url',
MagentoFrameworkDBDdlTable::TYPE_TEXT,
255,
['nullable' => false],
'Url'
)
->addColumn(
'name',
MagentoFrameworkDBDdlTable::TYPE_TEXT,
255,
['nullable' => false],
'Name'
)
->addColumn(
'phrase',
MagentoFrameworkDBDdlTable::TYPE_TEXT,
255,
[],
'Phrase'
)
->addColumn(
'logo',
MagentoFrameworkDBDdlTable::TYPE_TEXT,
255,
[],
'Logo'
)
->addColumn(
'banner',
MagentoFrameworkDBDdlTable::TYPE_TEXT,
255,
[],
'Banner'
)
->addColumn(
'author',
MagentoFrameworkDBDdlTable::TYPE_TEXT,
255,
['nullable' => false],
'Author'
)
->addColumn(
'author_photo',
MagentoFrameworkDBDdlTable::TYPE_TEXT,
255,
['nullable' => false],
'Author Photo'
)
->addColumn(
'desc',
MagentoFrameworkDBDdlTable::TYPE_TEXT,
'64k',
[],
'Desc'
)
->addColumn(
'status',
MagentoFrameworkDBDdlTable::TYPE_SMALLINT,
null,
['nullable' => false, 'default' => 1],
'Status'
)
->addColumn(
'created_at',
MagentoFrameworkDBDdlTable::TYPE_TIMESTAMP,
null,
['nullable' => false, 'default' => MagentoFrameworkDBDdlTable::TIMESTAMP_INIT],
'Created At'
)->addColumn(
'updated_at',
MagentoFrameworkDBDdlTable::TYPE_TIMESTAMP,
null,
['nullable' => false, 'default' => MagentoFrameworkDBDdlTable::TIMESTAMP_INIT_UPDATE],
'Updated At'
)->setComment("Shop Table");
$setup->getConnection()->createTable($table);
$setup->endSetup();
}
}
2
Answers
Updating from the scripts to
declarative schema
worked for me. For anyone using Magento 2.3 and above it seems to be a must.Table Scheme Example:
See more: Magento docs
Try below steps:
I have tried and table is creating on my system.