I have a migration in Yii2, where I try create a table. I set charset for table, but I don't know how to set charset for particular column.
For example:
$this->createTable('some_table', [
'column_1' => $this->string(64)->notNull(),
'column_2' => $this->integer()->notNull(),
'column_3' => $this->integer(),
], 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB');
In above code I want to set charset "utf8-unicode-ci" for column_1. How to do that?
To run specific migration, you can mark(skip) migrations upto just before one you want run. You can mark migration by using one of following command: Using timestamp to specify the migration yii migrate/mark 150101_185401. Using a string that can be parsed by strtotime() yii migrate/mark "2015-01-01 18:54:01"
Here is how I try to add FK: $this->addForeignKey('FK_user_profile', 'tbl_profile', 'user_id', 'tbl_user', 'id', 'CASCADE', 'CASCADE');
Use append().
$this->createTable('some_table', [
'column_1' => $this->string(64)->notNull()->append('CHARACTER SET utf8 COLLATE utf8_unicode_ci'),
'column_2' => $this->integer()->notNull(),
'column_3' => $this->integer(),
], 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB');
Is it just an example? Because you don't have to set charset for a single column when it's the same as for the whole table.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With