EN ES
Home > Web development > Laravel Tutorials > Fix Tableseeder Dont Exist Php Artisan Migrate Seed Laravel 5

Fix Tableseeder Dont Exist Php Artisan Migrate Seed Laravel 5

Diego Cortés
Diego Cortés
September 10, 2016
Fix Tableseeder Dont Exist Php Artisan Migrate Seed Laravel 5

Hello everyone!

When working on a Laravel 5 project and creating a new seeder, we add it to our DatabaseSeeder. In this example, we have added the ReportsTableSeeder seeder, leaving our DatabaseSeeder file as follows:

<?php

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $this->call(UsersTableSeeder::class);
        $this->call(ReportsTableSeeder::class);
    }
}

So far so good, when we run

php artisan migrate --seed

Sometimes it throws the following error:

[ReflectionException]
Class ReportsTableSeeder does not exist

Here we have different options, I will list the ones that occur to me at this moment:

  • Clearly the file does not exist
  • The file exists but the name of the class does not correspond (in this example the class must be class ReportsTableSeeder extends Seeder)

Once we confirm that all this is fine and we do not have any of these problems, that is, our file exists within the seeders folder of our project and the name of the class is correct, the solution to this is to clear the cache and optimize our Loader for this let's see the solution

Solution:

We execute all these commands in the following order:

php artisan optimize
php artisan cache:clear
php artisan route:clear
php artisan view:clear
php artisan config:clear
It is not necessary to execute them all, but I recommend doing so if you are in the development phase.

Once these commands have been executed one by one, we must delete the tables created previously by executing:

php artisan migrate --seed

If it gives an error, it is likely that we have other seeders before our not found seeder, and this has created the other tables. To solve this, we access our database and delete the created tables. Once the tables have been deleted, we repeat the process by executing:

php artisan migrate --seed

And finally now we can process our ReportsTableSeeder seeder 😀

I hope it helps more than one person.

Diego Cortés
Diego Cortés
Full Stack Developer, SEO Specialist with Expertise in Laravel & Vue.js and 3D Generalist

Categories

Page loaded in 32.70 ms