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

Chris Schmitz picture Chris Schmitz · Mar 4, 2016 · Viewed 13.1k times · Source

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 the skills migration file before the people 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 in skills is looking for a primary key in people that doesn't exist yet.

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.

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:

artisan error

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?

Answer

Joseph Silber picture Joseph Silber · Mar 4, 2016

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

composer dump-autoload