【发布时间】:2015-12-22 05:42:23
【问题描述】:
我想使用迁移类方法删除表。
这是我的迁移课程:
use yii\db\Schema;
use yii\db\Migration;
class m130524_201442_init extends Migration
{
public function up()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
}
$this->createTable('{{%user}}', [
'id' => Schema::TYPE_PK,
'username' => Schema::TYPE_STRING . ' NOT NULL',
'auth_key' => Schema::TYPE_STRING . '(32) NOT NULL',
'password_hash' => Schema::TYPE_STRING . ' NOT NULL',
'password_reset_token' => Schema::TYPE_STRING,
'email' => Schema::TYPE_STRING . ' NOT NULL',
'firstname' => Schema::TYPE_STRING,
'status' => Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 10',
'created_at' => Schema::TYPE_INTEGER . ' NOT NULL',
'updated_at' => Schema::TYPE_INTEGER . ' NOT NULL',
], $tableOptions);
}
public function down()
{
$this->dropTable('{{%user}}');
}
}
我使用 yii migrate/to 130524_201442 迁移了这个类。之后我做了很多其他的迁移,现在我想删除用户表,所以我尝试了下面的命令,
yii migrate safeDown console\migrations\m130524_201442_init.php
yii migrate down console\migrations\m130524_201442_init.php
输出:
D:\Projects\wamp\www\yiiadvanced>yii migrate down console\migrations\m130524_201442_init.php
Yii Migration Tool (based on Yii v2.0.5)
No new migration found. Your system is up-to-date.
也试过这个:
yii migrate/down 130524_201442
输出
D:\Projects\wamp\www\yiiadvanced>yii migrate/down 130524_201442
Yii Migration Tool (based on Yii v2.0.5)
Total 2 migrations to be reverted:
m151222_063506_roles
m130524_201442_init
Revert the above migrations? (yes|no) [no]:
如果我输入“yes”,那么它会恢复两者,但我只想删除 m130524_201442_init。
那么,我应该使用哪个命令?
【问题讨论】:
-
请显示错误信息。
-
不要运行
migrate/down 130524_201442。运行migrate/down 1之类的东西来恢复最后一个迁移,migrate/down 2来恢复最后两个,等等。
标签: php yii2 database-migration yii2-advanced-app