8

I have a fresh Laravel installation. I have moved over code from a github repository that is a Laravel project, same version (5.3).

Everything works fine, except for some reason the database seeds wont' run.

For example, I can migrate from the github loaded migrations in the new Laravel installation, just as I would on the server that pushed the migrations to github in the first place.

But I can't do php artisan db:seed, which means my beautiful little database is empty! >:(

I get: ReflectionException Class does not exist

What I have tried:

  1. php artisan optimize
  2. php artisan clear:cache
  3. composer clearcache
  4. composer dump-autoload

None of which have solved my problem. Everything in DatabaseSeeder is spelled correctly and the classes -do- exist, they work fine on my other server, and again, this fresh install now has all the same files as my origin server, thanks to Github.

DatabaseSeeder.php:

<?php

use Illuminate\Database\Seeder;

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

Edit - Stack Trace:

2017-06-14 19:11:00] local.ERROR: ReflectionException: Class UserTablesSeeder does not exist in /var/www/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php:749
Stack trace:
#0 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(749): ReflectionClass->__construct('UserTablesSeede...')
#1 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(644): Illuminate\Container\Container->build('UserTablesSeede...', Array)
#2 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(709): Illuminate\Container\Container->make('UserTablesSeede...', Array)
#3 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Seeder.php(55): Illuminate\Foundation\Application->make('UserTablesSeede...')
#4 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Seeder.php(43): Illuminate\Database\Seeder->resolve('UserTablesSeede...')
#5 /var/www/laravel/database/seeds/DatabaseSeeder.php(14): Illuminate\Database\Seeder->call('UserTablesSeede...')
#6 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Console/Seeds/SeedCommand.php(63): DatabaseSeeder->run()
#7 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(2292): Illuminate\Database\Console\Seeds\SeedCommand->Illuminate\Database\Console\Seeds\{closure}()
#8 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Console/Seeds/SeedCommand.php(64): Illuminate\Database\Eloquent\Model::unguarded(Object(Closure))
#9 [internal function]: Illuminate\Database\Console\Seeds\SeedCommand->fire()
#10 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(508): call_user_func_array(Array, Array)
#11 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Console/Command.php(169): Illuminate\Container\Container->call(Array)
#12 /var/www/laravel/vendor/symfony/console/Command/Command.php(261): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Console/Command.php(155): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /var/www/laravel/vendor/symfony/console/Application.php(817): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /var/www/laravel/vendor/symfony/console/Application.php(185): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Database\Console\Seeds\SeedCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /var/www/laravel/vendor/symfony/console/Application.php(116): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(121): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 /var/www/laravel/artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#19 {main}  
13
  • Have you made a database seeder? Commented Jun 14, 2017 at 19:22
  • If so, please provide that code Commented Jun 14, 2017 at 19:22
  • @Derek code added Commented Jun 14, 2017 at 19:23
  • My apologies, I mean the UserTableSeeder code Commented Jun 14, 2017 at 19:25
  • 1
    UserTablesSeeder vs UserTableSeeder, Tables vs Table Commented Jun 14, 2017 at 19:55

4 Answers 4

19

try running

composer dump-autoload

especially if you have recently edited the name of your seeder file

Sign up to request clarification or add additional context in comments.

1 Comment

thank you! this is better than any other methods. this should be the accepted answer.
1

I got around the problem by picking out an individual class:

php artisan db:seed --class=UserTableSeeder

As oppose to db:seed without any arguments, however I would still like to know why I have to do this.

Again, I don't have UserTablesSeederanywhere in my code so not sure why the log shows this is the seed attempt when I never declare that.

It's always UserTableSeeder without the s in Table.

Edit: And now my custom middleware doesn't work... seems to be an issue with the fresh install not liking some of the new code from github... if anyone can provide a better answer I will gladly accept.

4 Comments

Still could be a composer issue. Remove the vendor dir completely and the composer.lock file. After that run composer again for a fresh install. If you can, check the vendor/composer dir and grep for UserTables somewhere in the autoload files.
@Robert Okay will try this and get back to you. I will just install and pull from github all over and see if I can spot anything going wrong. Thanks for your help.
I'm having this problem now. Know the answer?
Weird. When I ran php artisan db:seed --env=testing I got Class UsersTableSeeder does not exist, so then I ran php artisan make:seeder UsersTableSeeder but got Seeder already exists!. Bizarre. I deleted the file and then re-ran the maker, and everything works now.
0

For Laravel 6.0, changing

$this->call(UserTableSeeder::class);

to

$this->call('UserTableSeeder');

Did the trick for me.

1 Comment

Where to change this
0

I deleted the seed file and re-make it, all works fine.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.