首页 > 解决方案 > 错误的迁移称为

问题描述

我有 2 个迁移,第一个具有以下名称2019_11_06_171637_create_settings_table.php和结构:

class CreateSettingsTable extends Migration
{
  public function up()
  {
    Schema::create('settings', function (Blueprint $table) {
      //code
    });
  }
  //function down
}

第二个具有以下名称2020_07_08_246856_create_settings_table.php和结构:

class CreateAnotherSettingsTable extends Migration
{
  public function up()
  {
    Schema::create('another_settings', function (Blueprint $table) {
      //code
    });
  }
  //function down
}

当我运行php artisan migrate所有迁移顺利时,直到Migrating: 2020_07_08_246856_create_settings_table- 它试图运行 previos migration( 2019_11_06_171637_create_settings_table.php) 并触发异常Table 'settings' already exists

这是否意味着迁移文件的名称在日期和数字之后必须是唯一的?

标签: laravellaravel-migrations

解决方案


我在某处读到 Laravel 使用迁移的文件名来调用迁移的正确类。我试图查找有关此的一些文档或参考,但我再也找不到了。您当前有两次相同的文件名(如果您忽略时间戳部分),这会导致 Laravel 两次调用同一个类。

如果您将第二个文件(具有 CreateAnotherSettingsTable 类的文件)重命名为2020_07_08_246856_create_another_settings_table.php,您的问题将得到解决。


推荐阅读