Before creating the files, need to create the Setup folder at app/code/Or**/En**/Setup
After created the folders, need create a InstallSchema.php file in app/code/Or**/En**/Setup/InstallSchema.php And paste the below code:

namespace or**\En**\Setup;

use Magento\Framework\Setup\InstallSchemaInterface;

use Magento\Framework\Setup\ModuleContextInterface;

use Magento\Framework\Setup\SchemaSetupInterface;

 

class InstallSchema implements InstallSchemaInterface

{

public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)

{

$installer = $setup;

$installer->startSetup();

 

if ( ! $installer->tableExists(‘order_enquiry_items’)) {

$table = $installer->getConnection()->newTable(

$installer->getTable(‘order_enquiry_items’)

)

->addColumn(

‘id’,

\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,

null,

[

‘identity’ => true,

‘nullable’ => false,

‘primary’  => true,

‘unsigned’ => true,

],

‘ID’

)

->addColumn(

‘name’,

\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,

255,

[‘nullable => false’],

‘Name’

)

->addColumn(

‘client_id’,

\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,

255,

[‘nullable => false’],

‘Client Id’

)

->addColumn(

‘order_number’,

\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,

255,

[‘nullable => false’],

‘Order Number’

)

->addColumn(

‘enquiry_content’,

\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,

’64k’,

[],

‘Enquiry Content’

)

->addColumn(

‘attachment’,

\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,

255,

[],

‘Attachment’

)

->addColumn(

‘enabled’,

\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,

1,

[],

‘Enabled’

)

->addColumn(

‘created_at’,

\Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,

null,

[],

‘Created At’

);

$installer->getConnection()->createTable($table);

}

$installer->endSetup();

}

}

Related Article

0 thoughts on “Create Custom Database Table Or InstallSchema in Magento 2”

Leave a Reply