我需要清除哪些 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
What Laravel cache do I need to clear to remove error about missing migration file?
提问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 people
and 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 artisan
I accidentally created the skills
migration file before the people
migration.
当我通过创建迁移时,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 skills
file has a smaller timestamp prefix in the name (17:42:21 comes before 17:42:27). This means the foreign key constraint in skills
is looking for a primary key in people
that 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.php
to 2016_02_24_170000_create_people_table.php
.
为了解决这个问题,我将文件重命名2016_02_24_174227_create_people_table.php
为2016_02_24_170000_create_people_table.php
.
This fix worked, but now whenever I php artisan migrate:refresh
my tables, I get an error saying that artisan is somehow still looking for the old people file:
此修复程序有效,但现在每当我php artisan migrate:refresh
我的表时,我都会收到一个错误消息,说工匠仍在以某种方式寻找老人文件:
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