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

Latest Article

Blog

Samsung Galaxy S8 might get a Portrait Mode with the next update

One of the hottest cell phone camera includes this year has seemingly been the Portrait mode, which enables a client to obscure the foundation of a subject along these lines giving more profundity to the Read more…

Blog

Huawei Mate 10 Lite with 18:9 display and four cameras declare

Huawei declare its leaders Mate 10 and Mate 10 Pro. In any case, in an unexpected move, Huawei has now quietly declared the spending gadget. The Huawei Mate 10 Lite too accompanies a stretched 5.9-inch Read more…

Blog

Xiaomi becomes India’s fastest growing smartphone brand

Riding on the accomplishment of its Redmi Note 4 gadget, Xiaomi has turned into the quickest developing cell phone mark in the second from last quarter of 2017, with a development of 292 for every Read more…