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

Migrations

When working with Migations, the migrations of databases in the Laravel, mainly in the initial development phase of a project, it is often used the execution of migrations with the command php artisan migrate.

It is also common to back down migrations to make hits on migration scripts without the need to create new portions of code to change tables, so the return on migrations for improvements in the database structure is generated with the command php artisan migrate:rollback.

Error class not found when executing php artisan migrate:rollback

Exactly with the return of migrations: php artisan migrate:rollback, the exception of error is released, unfortunately when it happens once, it happens with an annoying frequency.

In general this exception and the error message present the following pile of messages on 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/coletor/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:219
                                                             
  [Symfony\Component\Debug\Exception\FatalErrorException]  
  Class 'CreateAlunosTable' not found

Fixing the exception of php artisan migrate:rollback

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 is most of the time the lack of updating the Autoad File generated by the composer. For several reasons this can happen.

To correct, perform the composer’s Autoloading Dump on the terminal’s command line in the root directory of your project:

composer dump-autoload

If the problem persists, first clean the compilation cache generated by the previous Dump and run the command again:

php artisan clear-compiled
composer dump-autoload

If the compiled cache is not updated, it may be necessary to manually delete the file vendor/compiled.php and then perform the steps above again.

php artisan migrate:rollback without errors

After the autoader updates and cache cleaning 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