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}
In such situation, the migration service failed to inject the move request because the user failed validation. This means that we don’t have a move request for this user and therefore will have no move report.
In cases where the error message on the migration user is not so obvious and you still don’t have a move request created for it, you can check Get-MigrationUserStatistics with DiagnosticInfo verbose switch: Get-MigrationUserStatistics <user identity> -DiagnosticInfo verbose |FL and see if any more details found.
Note: For a move request to be in a Failed state, we would need to have a permanent failure. Too many transient failures (usually more than 60) will eventually cause a permanent failure. Too many transient failures can also slow down your migration considerably.
So there are a few things you can do to fix the "Class '' not found" in PHP. Typically it's just a typo or a uppercase where it should be lower or vice versa, in the namespace.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With