Yii Framework-yic migration命令不起作用 [英] Yii Framework - yic migrate command doesn't work
问题描述
我正在尝试在safeUp()方法中使用Yii db迁移创建表。但是,当我使用 ./yiic migration命令时,该命令运行成功,但是该表未出现在数据库中。以下是迁移文件中的代码:
I am trying to create a table using Yii db migration in safeUp() method. However, when I use the "./yiic migrate" command, it runs successfully but the table doesn't appear in the database. The following is code from the migration file:
<?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');
}
}
我尝试使用以下建议对类似问题的评论,例如为migration命令提供'up'或'safeUp'参数。我还检查了console.php文件,并将其配置为正确的数据库。
I tried using a few suggestions from comments on similar issue like, providing 'up' or 'safeUp' parameter to the migrate command. I also checked the console.php file and it is configured to the right database. What else could be the reason for not creating the table in the database?
推荐答案
您应该提供 up
或 safeUp
方法。因此,删除班级中空的 up
方法:
You should provide either the up
or safeUp
method. So remove the empty up
method in your class:
<?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');
}
}
这篇关于Yii Framework-yic migration命令不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!