Php 如何在一个类中迁移和插入值以及在yii 1中迁移
我的迁移文件中有以下代码:Php 如何在一个类中迁移和插入值以及在yii 1中迁移,php,yii,yii1.x,Php,Yii,Yii1.x,我的迁移文件中有以下代码: public function up(){ $this->execute($this) 创建表(如果不存在)`ad_court`( `id`int(11)非空自动增量, `name`varchar(255)不为空, 主键(`id`) )ENGINE=InnoDB默认字符集=utf8自动增量=18;'); $this->insert('ad_court',数组( “名称”=>“名称”, )); $this->insert('ad_court',数组( “名称”=>“Фа
public function up(){
$this->execute($this)
创建表(如果不存在)`ad_court`(
`id`int(11)非空自动增量,
`name`varchar(255)不为空,
主键(`id`)
)ENGINE=InnoDB默认字符集=utf8自动增量=18;');
$this->insert('ad_court',数组(
“名称”=>“名称”,
));
$this->insert('ad_court',数组(
“名称”=>“Фаааааааааааааа,
));
}
但是,当我迁移时,它会显示错误消息:
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.
我需要创建一个新表并在其中插入值。如何在一个迁移类中执行此操作?由于用户有此代码,您可以使用此代码:
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');
}
}
我创建了迁移代码。但是,我需要创建表并在其中插入值。在我的示例中,如果删除值(用于插入到表中),它将起作用。在其他情况下,它不会在创建的表中工作?错误是,它不存在,如果不存在,为什么不使用$this->createTable,这是我的点检查,也是我找到答案的原因(它没有说yii的版本,但似乎是yii1)。我在植入符号('')时犯了错误。