YII MIGRATIONS AND BU DEFAULT VALUES FOR TABLE COLUMNS

Royce Roy

Total Post:149

Points:1043
Posted by  Royce Roy
PHP 
PHP
 2095  View(s)
Ratings:
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! 

  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: YII migrations and bu default values for table columns

    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.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!