我想使用遷移類方法刪除表。Yii2:使用遷移刪除表
這是我的移民類:
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}}');
}
}
我遷移使用警予遷移/這個類130524_201442。從那以後,我做了很多其他的遷移,現在我想刪除用戶表,所以我嘗試下面的命令,
yii migrate safeDown console\migrations\m130524_201442_init.php
yii migrate down console\migrations\m130524_201442_init.php
OUTPUT:
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
OUTPUT
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]:
如果我輸入「是」,那麼它將恢復兩個,但我只想刪除m130524_201442_init。
那麼,我應該使用哪個命令?
請,顯示錯誤消息。 – Psyhos
不要運行'migrate/down 130524_201442'。運行'migrate/down 1'來恢復最後一次遷移,'migrate/down 2'恢復最後兩次遷移等。 – Beowulfenator