Yii Framework - yic migrate command doesn't work

﹥>﹥吖頭↗ 提交于 2019-12-25 05:24:16

问题


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');
}

}

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?


回答1:


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');
}

}


来源:https://stackoverflow.com/questions/18126773/yii-framework-yic-migrate-command-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!