我正在尝试使用safeUp()方法中的Yii-db迁移创建一个表。但是,当我使用"./yiic migrate"命令时,它会成功运行,但表不会出现在数据库中。以下是迁移文件中的代码:
<?php
class m130808_123826_test_table extends CDbMigration
{
public function up()
{
}
public function down()
{
echo "m130808_123826_test_table does not support migration down.'n";
return false;
}
public function safeUp()
{
$this->createTable('tbl_test', array(
'test_field1' => 'int(10)',
'test_field2' => 'string NOT NULL',
), 'ENGINE=InnoDB');
}
public function safeDown()
{
$this->dropTable('tbl_test');
}
}
我尝试使用类似问题评论中的一些建议,比如为migrate命令提供"up"或"safeUp"参数。我还检查了console.php文件,并将其配置为正确的数据库。不在数据库中创建表的其他原因是什么?
您应该提供up
或safeUp
方法。因此,删除类中的空up
方法:
<?php
class m130808_123826_test_table extends CDbMigration
{
public function down()
{
echo "m130808_123826_test_table does not support migration down.'n";
return false;
}
public function safeUp()
{
$this->createTable('tbl_test', array(
'test_field1' => 'int(10)',
'test_field2' => 'string NOT NULL',
), 'ENGINE=InnoDB');
}
public function safeDown()
{
$this->dropTable('tbl_test');
}
}