首页 > 解决方案 > 尝试在不同文件夹中运行两个具有相同名称的迁移时出现问题 Laravel

问题描述

我的迁移中有两个文件夹:

在每一个里面我都有一个用户的迁移,比如:create_users_table.

并且文件夹内的每个迁移都与不同的数据库有不同的连接,例如:

Schema::connection('mysql_simulator')
    ->create('users', function (Blueprint $table) {
    $table->id();
    $table->string('name');
    $table->string('email')->unique();
    $table->rememberToken();
    $table->timestamps();
});

问题是: Laravel 不允许我正确运行这些迁移。

当我尝试运行此命令时:php artisan migrate --path="database/migrations/simulator"

users表正常迁移,但如果之后我尝试使用tasks文件夹运行相同的操作:php artisan migrate --path="database/migrations/tasks"

我收到了这个错误:Nothing to migrate.

但是,如果我尝试从tasks文件夹重置我的迁移:php artisan migrate:reset --path="database/migrations/tasks

它向我表明:

Migration not found: 2021_02_13_194359_create_textures_table
Migration not found: 2021_02_04_224957_create_image_simulation_table
Migration not found: 2021_02_03_192318_create_images_table
Migration not found: 2021_01_29_170555_create_simulations_table
Migration not found: 2021_01_29_170326_create_addresses_table
Migration not found: 2021_01_29_170138_create_phones_table
Migration not found: 2019_08_19_000000_create_failed_jobs_table
Migration not found: 2014_10_12_100000_create_password_resets_table
Migration not found: 2014_10_12_000000_create_users_table
Migration not found: 2021_03_10_213837_create_users_table

基本上,它向我显示了另一个文件夹中的所有表(不是我运行命令的那个)我运行了我的tasks迁移,但它告诉我我所有的simulator迁移都没有找到。

所以我不知道正在发生这种情况,似乎 Laravel 正在读取来自不同文件夹的所有迁移,我只需要在不同的文件夹中创建相同的迁移名称并运行它而不会发生冲突,在 Laravel 中是否可能?

标签: laravel

解决方案


可能这些是您在成功迁移后从项目迁移目录中删除它们的迁移,当您运行php artisan migrate Laravel 时,将成功记录在数据库的迁移表中,因此当您删除它们时,会出现此错误,请尝试从中删除它们迁移表也


推荐阅读