Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

specifying the length of string in Yii migration

Tags:

php

migration

yii

I wish to create a migration whose up method will execute the create_table function.

For example :

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');
    }
}

How do I specify the length of a field in the migration ? Eg. What would I write if I have to specify that length of the title field should be 100 .

like image 416
lorefnon Avatar asked May 29 '11 09:05

lorefnon


1 Answers

Hey! I believe this was an addition they did last year. I havent tried it, but doesn't this work?

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

Also, in this site you'll find information which can be helpful, as well as here. Good luck with this!

like image 150
Soph Avatar answered Sep 29 '22 13:09

Soph