1

我已经通过一次迁移创建了插件。我的 version.yaml 是

1.0.1: First version of user
1.0.2:
    - Added new fields to User model
    - alter_table_users_add_contact_fields.php

我的更新目录包含一个迁移文件alter_table_users_add_contact_fields.php

<?php

namespace Mnv\Reminder\Updates;

use Schema;
use October\Rain\Database\Updates\Migration;

class CreateTableNewsRead extends Migration
{
    protected $table = 'mnv_news_read';

    public function up()
    {
        Schema::create($this->table, function($table)
        {
            $table->engine = 'InnoDB';
            $table->increments('id');

            $table->integer('news_id');
            $table->foreign('news_id')->references('id')->on('rainlab_blog_posts')->onUpdate('cascade')->onDelete('cascade');

            $table->integer('user_id');
            $table->foreign('user_id')->references('id')->on('users')->onUpdate('cascade')->onDelete('cascade');

            $table->timestamp('read_at');

            $table->index([
                'news_id',
                'user_id',
            ]);

            $table->index([
                'user_id',
                'news_id',
            ]);
        });
    }

    public function down()
    {
        Schema::dropIfExists($this->table);
    }
}

我已使用控制台命令成功运行此迁移php artisan october:up

但现在我想回滚这个迁移。正如我所见,表中没有关于此迁移的信息migrations。所以我不能使用命令回滚这个迁移php artisan migrate:rollback

我发现有关插件版本的信息包含在表中system_plugin_versions。我已经手动删除了我的表并mnv_news_read从表中手动删除了相应的记录。system_plugin_versionssystem_plugin_history

drop table mnv_news_read;
delete from system_plugin_history where code = 'Mnv.Reminder';
delete from system_plugin_versions where code = 'Mnv.Reminder';

之后,我再次尝试跑步php artisan october:up。它成功地完成了。

我的问题是如何正确回滚插件的迁移?

4

2 回答 2

3

回滚迁移的一种方法是通过管理控制面板中的构建器插件(如果您尚未安装此插件,请确保先安装)。

  1. 选择构建器插件菜单(从页面顶部)
  2. 选择您的插件(通过单击箭头“>”按钮)
  3. 从左侧菜单中,选择Versions
  4. 选择要回滚的版本
  5. 点击Rollback version按钮
于 2017-06-28T08:06:22.133 回答
1

根据文档,您可以在控制台中运行命令:

php artisan plugin:rollback AuthorName.PluginName 1.2.3
于 2021-04-20T07:07:55.180 回答