how to add collation( utf8_general_ci) using install schema in magento2?
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
I want to create table using install schema in magento2 with column collation( utf8_general_ci) .
how to do this?
magento2 install-script
add a comment |Â
up vote
1
down vote
favorite
I want to create table using install schema in magento2 with column collation( utf8_general_ci) .
how to do this?
magento2 install-script
Happy to help !! Happy Coding :)
– Rohan Hapani
39 mins ago
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I want to create table using install schema in magento2 with column collation( utf8_general_ci) .
how to do this?
magento2 install-script
I want to create table using install schema in magento2 with column collation( utf8_general_ci) .
how to do this?
magento2 install-script
magento2 install-script
asked 57 mins ago


Rutvee Sojitra
1,2351119
1,2351119
Happy to help !! Happy Coding :)
– Rohan Hapani
39 mins ago
add a comment |Â
Happy to help !! Happy Coding :)
– Rohan Hapani
39 mins ago
Happy to help !! Happy Coding :)
– Rohan Hapani
39 mins ago
Happy to help !! Happy Coding :)
– Rohan Hapani
39 mins ago
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
Add this below script in InstallSchema.php file :
<?php
namespace VendorNameModuleNameSetup;
use MagentoFrameworkSetupInstallSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
use MagentoFrameworkDBDdlTable;
class InstallSchema implements InstallSchemaInterface
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
$installer = $setup;
$installer->startSetup();
// Get vendor_sampletable table
$tableName = $installer->getTable('vendor_sampletable');
// Check if the table already exists
if ($installer->getConnection()->isTableExists($tableName) != true)
// Create vendor_sampletable 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'
)
->addColumn(
'description',
Table::TYPE_TEXT,
null,
['nullable' => false, 'default' => ''],
'Description'
)
->addColumn(
'summary',
Table::TYPE_TEXT,
null,
['nullable' => false, 'default' => ''],
'Summary'
)
->addColumn(
'created_at',
Table::TYPE_DATETIME,
null,
['nullable' => false],
'Created At'
)
->addColumn(
'status',
Table::TYPE_SMALLINT,
null,
['nullable' => false, 'default' => '0'],
'Status'
)
->setComment('Table Comment')
->setOption('type', 'InnoDB')
->setOption('charset', 'utf8')
->setOption('collate', 'utf8_general_ci');
$installer->getConnection()->createTable($table);
$installer->endSetup();
1
Good answer. So we can change charset and collate from setOption.
– Amit Bera♦
32 mins ago
Thanks @AmitBera. I take reference from /vendor/magento/framework/DB/Ddl/Table.php file
– Rohan Hapani
27 mins ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
Add this below script in InstallSchema.php file :
<?php
namespace VendorNameModuleNameSetup;
use MagentoFrameworkSetupInstallSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
use MagentoFrameworkDBDdlTable;
class InstallSchema implements InstallSchemaInterface
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
$installer = $setup;
$installer->startSetup();
// Get vendor_sampletable table
$tableName = $installer->getTable('vendor_sampletable');
// Check if the table already exists
if ($installer->getConnection()->isTableExists($tableName) != true)
// Create vendor_sampletable 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'
)
->addColumn(
'description',
Table::TYPE_TEXT,
null,
['nullable' => false, 'default' => ''],
'Description'
)
->addColumn(
'summary',
Table::TYPE_TEXT,
null,
['nullable' => false, 'default' => ''],
'Summary'
)
->addColumn(
'created_at',
Table::TYPE_DATETIME,
null,
['nullable' => false],
'Created At'
)
->addColumn(
'status',
Table::TYPE_SMALLINT,
null,
['nullable' => false, 'default' => '0'],
'Status'
)
->setComment('Table Comment')
->setOption('type', 'InnoDB')
->setOption('charset', 'utf8')
->setOption('collate', 'utf8_general_ci');
$installer->getConnection()->createTable($table);
$installer->endSetup();
1
Good answer. So we can change charset and collate from setOption.
– Amit Bera♦
32 mins ago
Thanks @AmitBera. I take reference from /vendor/magento/framework/DB/Ddl/Table.php file
– Rohan Hapani
27 mins ago
add a comment |Â
up vote
3
down vote
accepted
Add this below script in InstallSchema.php file :
<?php
namespace VendorNameModuleNameSetup;
use MagentoFrameworkSetupInstallSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
use MagentoFrameworkDBDdlTable;
class InstallSchema implements InstallSchemaInterface
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
$installer = $setup;
$installer->startSetup();
// Get vendor_sampletable table
$tableName = $installer->getTable('vendor_sampletable');
// Check if the table already exists
if ($installer->getConnection()->isTableExists($tableName) != true)
// Create vendor_sampletable 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'
)
->addColumn(
'description',
Table::TYPE_TEXT,
null,
['nullable' => false, 'default' => ''],
'Description'
)
->addColumn(
'summary',
Table::TYPE_TEXT,
null,
['nullable' => false, 'default' => ''],
'Summary'
)
->addColumn(
'created_at',
Table::TYPE_DATETIME,
null,
['nullable' => false],
'Created At'
)
->addColumn(
'status',
Table::TYPE_SMALLINT,
null,
['nullable' => false, 'default' => '0'],
'Status'
)
->setComment('Table Comment')
->setOption('type', 'InnoDB')
->setOption('charset', 'utf8')
->setOption('collate', 'utf8_general_ci');
$installer->getConnection()->createTable($table);
$installer->endSetup();
1
Good answer. So we can change charset and collate from setOption.
– Amit Bera♦
32 mins ago
Thanks @AmitBera. I take reference from /vendor/magento/framework/DB/Ddl/Table.php file
– Rohan Hapani
27 mins ago
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
Add this below script in InstallSchema.php file :
<?php
namespace VendorNameModuleNameSetup;
use MagentoFrameworkSetupInstallSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
use MagentoFrameworkDBDdlTable;
class InstallSchema implements InstallSchemaInterface
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
$installer = $setup;
$installer->startSetup();
// Get vendor_sampletable table
$tableName = $installer->getTable('vendor_sampletable');
// Check if the table already exists
if ($installer->getConnection()->isTableExists($tableName) != true)
// Create vendor_sampletable 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'
)
->addColumn(
'description',
Table::TYPE_TEXT,
null,
['nullable' => false, 'default' => ''],
'Description'
)
->addColumn(
'summary',
Table::TYPE_TEXT,
null,
['nullable' => false, 'default' => ''],
'Summary'
)
->addColumn(
'created_at',
Table::TYPE_DATETIME,
null,
['nullable' => false],
'Created At'
)
->addColumn(
'status',
Table::TYPE_SMALLINT,
null,
['nullable' => false, 'default' => '0'],
'Status'
)
->setComment('Table Comment')
->setOption('type', 'InnoDB')
->setOption('charset', 'utf8')
->setOption('collate', 'utf8_general_ci');
$installer->getConnection()->createTable($table);
$installer->endSetup();
Add this below script in InstallSchema.php file :
<?php
namespace VendorNameModuleNameSetup;
use MagentoFrameworkSetupInstallSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
use MagentoFrameworkDBDdlTable;
class InstallSchema implements InstallSchemaInterface
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
$installer = $setup;
$installer->startSetup();
// Get vendor_sampletable table
$tableName = $installer->getTable('vendor_sampletable');
// Check if the table already exists
if ($installer->getConnection()->isTableExists($tableName) != true)
// Create vendor_sampletable 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'
)
->addColumn(
'description',
Table::TYPE_TEXT,
null,
['nullable' => false, 'default' => ''],
'Description'
)
->addColumn(
'summary',
Table::TYPE_TEXT,
null,
['nullable' => false, 'default' => ''],
'Summary'
)
->addColumn(
'created_at',
Table::TYPE_DATETIME,
null,
['nullable' => false],
'Created At'
)
->addColumn(
'status',
Table::TYPE_SMALLINT,
null,
['nullable' => false, 'default' => '0'],
'Status'
)
->setComment('Table Comment')
->setOption('type', 'InnoDB')
->setOption('charset', 'utf8')
->setOption('collate', 'utf8_general_ci');
$installer->getConnection()->createTable($table);
$installer->endSetup();
edited 41 mins ago
answered 47 mins ago


Rohan Hapani
4,37621559
4,37621559
1
Good answer. So we can change charset and collate from setOption.
– Amit Bera♦
32 mins ago
Thanks @AmitBera. I take reference from /vendor/magento/framework/DB/Ddl/Table.php file
– Rohan Hapani
27 mins ago
add a comment |Â
1
Good answer. So we can change charset and collate from setOption.
– Amit Bera♦
32 mins ago
Thanks @AmitBera. I take reference from /vendor/magento/framework/DB/Ddl/Table.php file
– Rohan Hapani
27 mins ago
1
1
Good answer. So we can change charset and collate from setOption.
– Amit Bera♦
32 mins ago
Good answer. So we can change charset and collate from setOption.
– Amit Bera♦
32 mins ago
Thanks @AmitBera. I take reference from /vendor/magento/framework/DB/Ddl/Table.php file
– Rohan Hapani
27 mins ago
Thanks @AmitBera. I take reference from /vendor/magento/framework/DB/Ddl/Table.php file
– Rohan Hapani
27 mins ago
add a comment |Â
Â
draft saved
draft discarded
Â
draft saved
draft discarded
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f248001%2fhow-to-add-collation-utf8-general-ci-using-install-schema-in-magento2%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Happy to help !! Happy Coding :)
– Rohan Hapani
39 mins ago