代码之家  ›  专栏  ›  技术社区  ›  mrateb

yii2迁移以增加列长度

  •  4
  • mrateb  · 技术社区  · 6 年前

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

    使用 $this->alterColumn('my_table', 'text_column', 'string'); 将使列255保持原样。我正在考虑使用mysql将列更改为 文本 而不是 小精灵 ,但在yii2中有这样做的方法吗?

    1 回复  |  直到 6 年前
        1
  •  5
  •   rob006    6 年前

    改变 varchar 长度:

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

    将列类型更改为 text :

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

    你可以在 Migrations documentation .