我需要清除哪些 Laravel 缓存才能消除有关丢失迁移文件的错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35802395/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 13:20:40  来源:igfitidea点击:

What Laravel cache do I need to clear to remove error about missing migration file?

phplaraveldatabase-migrationlaravel-5.2artisan

提问by Chris Schmitz

I've got a couple of migrations for tables within my app. The tables are:

我在我的应用程序中对表进行了几次迁移。这些表是:

  • people
  • skills
  • media
  • notes
  • 人们
  • 技能
  • 媒体
  • 笔记

There is a one to many relationship between peopleand each of the other tables.

people每个其他表之间存在一对多关系。

// The people table definition

Schema::create('people', function (Blueprint $table) {
    $table->uuid('id');
    $table->primary('id');
    ...
    $table->timestamps();
});


// the skill table definition with the foreign key constraint referencing people

Schema::create('skills', function (Blueprint $table) {
    $table->uuid('id');
    $table->primary('id');
    $table->uuid('person_id');
    $table->foreign('person_id')
            ->references('id')->on('people')
            ->onDelete('cascade');
    ...
    $table->timestamps();
});

When I was creating the migrations via artisanI accidentally created the skillsmigration file before the peoplemigration.

当我通过创建迁移时,artisan我不小心在skills迁移之前创建了迁移文件people

This caused a problem because when you run php artisan migrate, the files are fired in timestamp order and if a primary key is not established before a foreign key constraint is defined you get an error, e.g.

这导致了一个问题,因为当您运行时php artisan migrate,文件按时间戳顺序触发,如果在定义外键约束之前未建立主键,则会出现错误,例如

The file:

文件:

2016_02_24_174227_create_people_table.php

Will fire afterthe file:

文件触发:

2016_02_24_174221_create_skills_table.php

Because the skillsfile has a smaller timestamp prefix in the name (17:42:21 comes before 17:42:27). This means the foreign key constraint in skillsis looking for a primary key in peoplethat doesn't exist yet.

因为skills文件在名称中具有较小的时间戳前缀(17:42:21 在 17:42:27 之前)。这意味着外键约束skills正在寻找people尚不存在的主键。

So to fix that, I renamed the file 2016_02_24_174227_create_people_table.phpto 2016_02_24_170000_create_people_table.php.

为了解决这个问题,我将文件重命名2016_02_24_174227_create_people_table.php2016_02_24_170000_create_people_table.php.

This fix worked, but now whenever I php artisan migrate:refreshmy tables, I get an error saying that artisan is somehow still looking for the old people file:

此修复程序有效,但现在每当我php artisan migrate:refresh我的表时,我都会收到一个错误消息,说工匠仍在以某种方式寻找老人文件:

artisan error

工匠错误

I tried clearing the application cache with php artisan cache:clear, but I still get the error.

我尝试使用 清除应用程序缓存php artisan cache:clear,但仍然出现错误。

Is there a particular cache I need to clear to remove the reference to the original migration file?

是否需要清除特定缓存才能删除对原始迁移文件的引用?

回答by Joseph Silber

It's not a cache issue. You just have to run composer again:

这不是缓存问题。你只需要再次运行 composer :

composer dump-autoload

回答by Santosh Ram Kunjir

Rollback your migration and check

回滚您的迁移并检查

migrate:rollback