YII2 migrate 相關操作

/**
 * {@inheritdoc}
 */
public function safeUp()
{
    //刪除一條數據
    $this->delete('membership_order',[
        'application_id' => 398
    ]);
}

/**
 * {@inheritdoc}
 */
public function safeDown()
{
    $this->dropTable('membership_order');
    return true;
}

 

   public function up()
    {
        //創建數據表test_table並且定義表中字段
        $this->createTable('test_table', [
            //`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY
            'id' => $this->primaryKey(),
            //`title` varchar(300) not null
            'title' => $this->string(300)->notNull(),
            //`content` text
            'content' => $this->text(),
            // `create_time` datetime
            'create_time' => $this->dateTime(),
        ]);

        //插入一條數據
        $this->insert('test_table',[
            'id' => 1,
            'title' => '哆啦A夢',
            'content' => '大雄'
        ]);
    }
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章