Reputation: 1708
I have a simple laravel project with migrations that run fine. I want to make one of them run first (so I can use that table in a foreign key constraint in a later migration), so I renamed that migration script by prepending "1_" so it's first in the list.
But when I run migrations since renaming the file, I get a fatal 'class not found' error for Class '152152CreatePeopleTable', from Migrator.php on line 324- see full stack trace below. (And when I rename the migration file back, the class is found again when I run migrations).
I updated the name in vendor/composer/autoload_classmap.php to match the updated file name (1_2015_09_06_152152_create_people_table.php), and searching in phpstorm, '152152_create_people' isn't found anywhere else except laravel.log, so there should be nowhere else that could have the old file name, right?
So I cleared cache and tried other recommendations from similar-sounding issues (thank you google/stackoverflow):
What else should I be checking/trying?
[2015-09-12 22:42:19] local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class '152152CreatePeopleTable' not found' in /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:324
Stack trace:
#0 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(133): Symfony\Component\Debug\Exception\FatalErrorException->__construct()
#1 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(118): Illuminate\Foundation\Bootstrap\HandleExceptions->fatalExceptionFromError()
#2 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(0): Illuminate\Foundation\Bootstrap\HandleExceptions->handleShutdown()
#3 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(129): Illuminate\Database\Migrations\Migrator->resolve()
#4 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(112): Illuminate\Database\Migrations\Migrator->runUp()
#5 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(85): Illuminate\Database\Migrations\Migrator->runMigrationList()
#6 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php(74): Illuminate\Database\Migrations\Migrator->run()
#7 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(502): Illuminate\Database\Console\Migrations\MigrateCommand->fire()
#8 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(502): call_user_func_array:{/home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php:502}()
#9 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Console/Command.php(150): Illuminate\Container\Container->call()
#10 /home/vagrant/Code/Family-laravel/vendor/symfony/console/Command/Command.php(259): Illuminate\Console\Command->execute()
#11 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Symfony\Component\Console\Command\Command->run()
#12 /home/vagrant/Code/Family-laravel/vendor/symfony/console/Application.php(878): Illuminate\Console\Command->run()
#13 /home/vagrant/Code/Family-laravel/vendor/symfony/console/Application.php(195): Symfony\Component\Console\Application->doRunCommand()
#14 /home/vagrant/Code/Family-laravel/vendor/symfony/console/Application.php(126): Symfony\Component\Console\Application->doRun()
#15 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(100): Symfony\Component\Console\Application->run()
#16 /home/vagrant/Code/Family-laravel/artisan(36): Illuminate\Foundation\Console\Kernel->handle()
#17 /home/vagrant/Code/Family-laravel/artisan(0): {main}()
#18 {main}
Upvotes: 6
Views: 4396
Reputation: 1168
php artisan dump-autoload
does not exists in Laravel 5, you can use composer dump-autoload
instead
Upvotes: 4
Reputation: 9835
Actually Laravel prefixes all migration classes with date so he can stay up to date on the current schema state, when you prefix your class with "1_", Laravel will not be able to parse it hence the error.
As a solution, rename your file to the oldest date in your project, something like 2014_01_06_152152_create_people_table.php
then run php artisan dump-autoload
(maybe you will need to drop all tables). But, keep in mind that this is not the appropriate solution, because:
Migrations are like version control for your database, allowing a team to easily modify and share the application's database schema.
Indeed, the best option to keep tracking your schema state is to create a new migration artisan make:migration add_person_forein_key_to_{your_table}
(maybe later, you no longer need this foreign key so you will just remove the file or create another migration to drop it). If you just started your project it's fine to just rename you migration, but if you work in a large project with many coworkers, I recommend you create a new migration.
Upvotes: 5