Laravel migrations: Class “not found”

前端 未结 16 1437
自闭症患者
自闭症患者 2020-12-12 14:38

I am deploying a Laravel barebone project to Microsoft Azure, but whenever I try to execute php artisan migrate I get the error:

[2015-06-13

相关标签:
16条回答
  • 2020-12-12 15:14

    I think it's late to answer this question but maybe this will help someone.

    If you changed the migration file name, be sure about its inner class name.

    For example, If I change a migration name from 2018_06_10_079999_create_admins_table.php to 2018_06_10_079999_create_managers_table.php so its inner class name must change from CreateAdminsTable to CreateManagerTable too.

    0 讨论(0)
  • 2020-12-12 15:16

    simply delete the row at your database on table migrations and that will fix the problem. It will not show anymore when you do migrations

    other way is to simple create the file it depends of what u want, in my case I wanted to get rid of this migration. :)

    0 讨论(0)
  • 2020-12-12 15:17

    Just make sure the following two files contain the correct class name and migration name :

    C:\xampp\htdocs\StuffSpot\vendor\composer\autoload_classmap.php C:\xampp\htdocs\StuffSpot\vendor\composer\autoload_static.php

    0 讨论(0)
  • 2020-12-12 15:19

    For PSR-4 Auto Loader Users (composer.json):

    Keep the migrations folder inside classmap array and do not include it inside psr-4 object under autoload head. As migrations' main class Migrator doesn't support namespacing. For example;

    "autoload": {
        "classmap": [
            "app/database/migrations"
        ],
        "psr-4": {
            "Acme\\controllers\\": "app/controllers"
        }
    }
    

    Then run:

    php artisan clear-compiled 
    php artisan optimize:clear
    composer dump-autoload
    php artisan optimize
    
    • First one clears all compiled autoload files.
    • Second clears Laravel caches (optional)
    • Third builds the autoloader for namespaced classes.
    • Fourth optimizes various parts of your Laravel app and builds the autoloader for non-namespaced classes.

    From this time on wards, you will not have to do this again and any new migrations will work correctly.

    0 讨论(0)
  • 2020-12-12 15:19

    I had foolishly put:

    namespace database\migrations;
    

    Inside my migration create_users_table.php [2014_10_12_000000_create_users_table.php]

    I was getting a similar error - Class 'CreateUsersTable' not found.

    Removing this line at the top solved this error.

    0 讨论(0)
  • 2020-12-12 15:21

    If you get the "Class not found error" when running migrations, please try running this command.

    composer dump-autoload 
    

    then re-issuing the migrate command. See more details in the offical site (#Running Migrations): http://laravel.com/docs/master/migrations#running-migrations

    0 讨论(0)
提交回复
热议问题