在Yii迁移中指定字符串的长度

lor*_*non 5 php migration yii

我希望创建一个迁移,其up方法将执行create_table函数.

例如 :

class m101129_185401_create_news_table extends CDbMigration
{
    public function up()
    {
        $this->createTable('tbl_news', array(
            'id' => 'pk',
            'title' => 'string NOT NULL',
            'content' => 'text',
        ));
    }

    public function down()
    {
        $this->dropTable('tbl_news');
    }
}

如何在迁移中指定字段的长度?例如.如果我必须指定标题字段的长度应为100,我会写什么.

Sop*_*oph 7

嘿! 我相信这是他们去年做的一个补充.我还没试过,但这不行吗?

public function up()
{
    $this->createTable('tbl_news', array(
        'id' => 'pk',
        'title' => 'varchar(20) NOT NULL',
        'content' => 'text',
    ));
}
Run Code Online (Sandbox Code Playgroud)

此外,在这个网站,你会找到有用的信息,以及这里.祝你好运!