What Laravel cache do I need to clear to remove error about missing migration file?
Solution 1
It's not a cache issue. You just have to run composer again:
composer dump-autoload
Solution 2
Rollback your migration and check
migrate:rollback
Related videos on Youtube
Chris Schmitz
Application engineer at Label Insight, web dev, and maker.
Updated on June 04, 2022Comments
-
Chris Schmitz almost 2 years
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.// 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 theskills
migration file before thepeople
migration.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.The file:
2016_02_24_174227_create_people_table.php
Will fire after the 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 inskills
is looking for a primary key inpeople
that doesn't exist yet.So to fix that, I renamed the file
2016_02_24_174227_create_people_table.php
to2016_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:I tried clearing the application cache with
php artisan cache:clear
, but I still get the error.Is there a particular cache I need to clear to remove the reference to the original migration file?
-
Chris Schmitz about 8 yearsfacepalm I forgot that the migrations are part of a composer classmap. Thanks for the help. I'll give you a check once I'm able to. You answered so fast that the time limit isn't up :P
-
yehanny over 4 yearsI had the same issue and this help me a LOT, thanks!
-
MarsAndBack almost 3 yearsThis didn't work for me;
php artisan migrate
is still giving a warning about a migration that exists on another code branch.