1

我的迁移文件中有以下代码:

public function up() {
    $this->execute('
        CREATE TABLE IF NOT EXISTS `ad_court` (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `name` varchar(255) NOT NULL,
        PRIMARY KEY (`id`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=18 ;');

    $this->insert('ad_court',array(
        'name' =>'Хўжалик суди',
    ));
    $this->insert('ad_court',array(
        'name' =>'Фуқаролик суди',
    ));
}

但是,当我迁移时,它显示错误消息:

 insert into ad_court ...exception 'CDbException' with message
      'CDbCommand failed to execute the SQL
 statement: SQLSTATE[42S02]: Base table or view not found: 
 1146 Table 'chamber_local_site.ad_court' doesn't exist.

我需要创建一个新表并在其中插入值。我怎样才能在一个迁移课程中做到这一点?

4

1 回答 1

1

作为用户指南,有该代码,您可以使用它:

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');
    }
}
于 2017-01-03T09:40:25.643 回答