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

17,515

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
Share:
17,515

Related videos on Youtube

Chris Schmitz
Author by

Chris Schmitz

Application engineer at Label Insight, web dev, and maker.

Updated on June 04, 2022

Comments

  • Chris Schmitz
    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 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?

  • Chris Schmitz
    Chris Schmitz about 8 years
    facepalm 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
    yehanny over 4 years
    I had the same issue and this help me a LOT, thanks!
  • MarsAndBack
    MarsAndBack almost 3 years
    This didn't work for me; php artisan migrate is still giving a warning about a migration that exists on another code branch.