Home > DeveloperSection > Forums > YII migrations and bu default values for table columns
Royce Roy
Royce Roy

Total Post:134

Points:938
Posted on    May-15-2013 8:15 AM

 PHP PHP 
Ratings:


 1 Reply(s)
 1660  View(s)
Rate this:
Hi Everyone!

public function up(){

        $this->createTable('POST', array(
            'id' => 'pk',
            'isremoved' => 'integer NOT NULL',
            'removaldate' => 'timestamp NULL',
            'post' => 'text NOT NULL',
            'creationdate' => 'timestamp NOT NULL',
        ));
}

This is the up function for migration. As u see it is query for creating new table. By default YII creates default value for timestamp column equal to CURRENT_TIMESTAMP and crates additional parameter and sets it equal to ON UPDATE CURRENT_TIMESTAMP.

I do not need current value for timestamp and I do not need to update this column on updating row. What i must to do? By the way, u use MySQL

Thanks in advance! 



AVADHESH PATEL

Total Post:604

Points:4228
Posted on    May-15-2013 8:56 AM

Hi Royce!

You have to set other default value, null for example

public function up(){
        $this->createTable('POST', array(
            'id' => 'pk',
            'isremoved' => 'integer NOT NULL',
            'removaldate' => 'timestamp DEFAULT NULL',
            'post' => 'text NOT NULL',
            'creationdate' => 'timestamp DEFAULT NULL',
        ));
}

I hope it help to you.

Don't want to miss updates? Please click the below button!

Follow MindStick