如何在Yii2的迁移中将charset设置为特定列

Rat*_*bek 6 migration character-encoding yii2

我在Yii2中进行了迁移,在那里我尝试创建一个表.我为表设置了charset,但我不知道如何为特定列设置charset.

例如:

$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');
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,我想为column_1设置charset"utf8-unicode-ci".怎么做?

Biz*_*ley 8

使用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');
Run Code Online (Sandbox Code Playgroud)

这只是一个例子吗?因为您不必为单个列设置charset,因为它与整个表的相同.