Yii2迁移以增加列长度

时间:2018-06-05 12:51:28

标签: mysql yii2 schema

在Yii2中,我希望创建一个迁移,将varchar列的字符限制从255更改为765.

使用$this->alterColumn('my_table', 'text_column', 'string');将使列255保持原样。我正在考虑使用mysql将列更改为 TEXT 而不是 Varchar ,但有没有办法在Yii2中执行此操作?

1 个答案:

答案 0 :(得分:5)

更改varchar长度:

$this->alterColumn('my_table', 'text_column', $this->string(765));

将列类型更改为text

$this->alterColumn('my_table', 'text_column', $this->text());

您可以在Migrations documentation中找到更多示例。