Search code examples
phplaravel-4database-migration

Laravel Fatal Error Class Not Found when migrating


  1. I've run artisan migrate:reset.

  2. I've deleted some of my migration files because I didn't need these tables anymore.

  3. I ran composer dump-autoload followed by artisan dump-autoload

  4. I ran artisan migrate and I keep getting this error:

    PHP Fatal error: Class 'Foo' not found in /vagrant/LaravelBackend/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php on line 297

I tried to:

  • Run again composer dump-autoload and artisan dump-autoload (also used artisan clear-compiled)

  • Remove the migration table and run artisan migrate:install

  • Remove the vendor and composer.lock file and run composer install

  • Search within my project with PHPStorm for class Foo. Didn't find anything.

    I keep getting the same error. It's the first time I run this since I updated to 4.2 if that could be related. Anything else I should be looking for?


Solution

  • I solved my problem by

    1. Removing all migration
    2. Running composer dump-autoload
    3. Adding them back one by one and running php artisan migrate
    4. Deleting those that caused Laravel to throw an error
    5. Create new migrations to replace the deleted ones

    I'm not sure why that worked but my guess is that I might have modified the class name of these problematic migrations in the past.

    I also found that renaming the migration with its initial name (The one throwed with the fatal error) also works for some of them.