Skip to content
Start » Laravel » How to solve Laravel class not found error in php artisan migrate:rollback

How to solve Laravel class not found error in php artisan migrate:rollback

If you are getting the error class not found when executing the command php artisan migrate:rollback in a project with Laravel framework, this article shows you how to resolve the error and perform the rollback.

migrations

when working with migrations, database migrations in Laravel, especially in the initial development phase of a project, it is often used to perform migrations with the command php artisan migrate.

It is also common to roll back migrations to make adjustments to the migration without the need to create new portions of code to change tables, so the return of migrations to improve the database structure is handled with the command php artisan migrate:rollback.

Error class not found when performing rollback

Exactly with the return migrations: php artisan migrate:rollback, the error exception is thrown, unfortunately when it happens once it ends up happening with an annoying frequency.

This exception and error message typically presents the following stack of messages in the console:

$ artisan migrate:rollback PHP Fatal error: Class 'CreateAlunosTable' not found in /var/www/coletor/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php on line 328 PHP Stack trace: PHP 1. {main}() /var/www/coletor/artisan:0 PHP 2. Illuminate\Foundation\Console\Kernel->handle() /var/www/coletor/artisan:36 PHP 3. Symfony\Component\Console\Application ->run() /var/www/coletor/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:94 PHP 4. Symfony\Component\Console\Application->doRun() /var/www /coletor/vendor/symfony/console/Symfony/Component/Console/Application.php:126 PHP 5. Symfony\Component\Console\Application->doRunCommand() /var/www/coletor/vendor/symfony/console/Symfony/ Component/Console/Application.php:195 PHP 6. Illuminate\Console\Command->run() /var/www/coletor/vendor/symfony/console/Symfony/Component/Console/Application.php:874 PHP 7. Symfony \Component\Console\Command\Command->run() /var/www/coletor/vendor/laravel/framework/src/Illuminate/ Console/Command.php:101 PHP 8. Illuminate\Console\Command->execute() /var/www/coletor/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:257 PHP 9. Illuminate \Container\Container->call() /var/www/coletor/vendor/laravel/framework/src/Illuminate/Console/Command.php:115 PHP 10. call_user_func_array() /var/www/coletor/vendor/laravel/ framework/src/Illuminate/Container/Container.php:523 PHP 11. Illuminate\Database\Console\Migrations\RollbackCommand->fire() /var/www/coletor/vendor/laravel/framework/src/Illuminate/Container/Container .php:523 PHP 12. Illuminate\Database\Migrations\Migrator->rollback() /var/www/coletor/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/RollbackCommand.php:59 PHP 13. Illuminate\Database\Migrations\Migrator->runDown() /var/www/coletor/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:172 PHP 14. Illuminate\Database\Migrations\Migrator-> resolve() /var/www/collector/vendor/laravel/framework/src/Illuminate/Datab ase/Migrations/Migrator.php:219 [Symfony\Component\Debug\Exception\FatalErrorException] Class 'CreateAlunosTable' not found

Fixing php artisan migrate:rollback exception

The correction of this small obstacle is very simple, and very common in the day-to-day development with Laravel and the autoloadings of PSR-4 created and organized by composer.

The cause most of the time is the lack of update of the file of autoload generated by Composer. For several reasons this can happen.

To fix, run composer autoloading dump from the terminal command line in your project root directory:

$ composer dump-autoload

If the problem persists, first clear the build cache generated by dump above and run the command again:

$ php artisan clear-compiled $ composer dump-autoload

If the compiled cache still does not update, you may need to manually delete the file vendor/compiled.php and then perform the above steps again.

php artisan migrate:rollback no errors

After the updates of autoload and cache clears performed, the expected result:

$ php artisan migrate:rollback Rolled back: 2018_05_14_184235_create_alunos_uepg_table Rolled back: 2018_05_13_184235_create_convenios_table Rolled back: 2018_05_12_184235_create_pais_table

keep up to date

Don't forget to follow me on twitter and sign the Mazer.dev channel on Youtube to receive updates on new articles, video lessons and free courses in software development and engineering.

More about Laravel

Best Practices for Writing Clean Code
Neste artigo apresento dicas para ao desenvolver um software, escrever com boas …
Engenharia de Software – Visão Geral
Este artigo apresenta uma visão geral da engenharia de software, que é …

Leave a Reply

Your email address will not be published.

en_USEnglish
%d bloggers like this: