how to add collation( utf8_general_ci) using install schema in magento2?

The name of the pictureThe name of the pictureThe name of the pictureClash 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?










share|improve this question





















  • Happy to help !! Happy Coding :)
    – Rohan Hapani
    39 mins ago
















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?










share|improve this question





















  • Happy to help !! Happy Coding :)
    – Rohan Hapani
    39 mins ago












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?










share|improve this question













I want to create table using install schema in magento2 with column collation( utf8_general_ci) .



how to do this?







magento2 install-script






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 57 mins ago









Rutvee Sojitra

1,2351119




1,2351119











  • 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




Happy to help !! Happy Coding :)
– Rohan Hapani
39 mins ago










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();







share|improve this answer


















  • 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










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























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();







share|improve this answer


















  • 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














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();







share|improve this answer


















  • 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












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();







share|improve this answer














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();








share|improve this answer














share|improve this answer



share|improve this answer








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












  • 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































Comments

Popular posts from this blog

List of Gilmore Girls characters

What does second last employer means? [closed]

One-line joke