Laravel Fatal Error Class Not Found when migrating

后端 未结 11 2112
后悔当初
后悔当初 2021-02-02 11:39
  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

相关标签:
11条回答
  • 2021-02-02 11:53

    I had the same problem. When I was hiting php artisan migrate:reset, I got Class 'CreateImagesTable' not found. And composer dump-autoload didn't help.

    My solution was very easy:

    1. php artisan make:migration create_images_table --create=images
    2. composer dump-autoload
    3. Then I got: SQLSTATE[HY000]: General error: 1 no such table: images (SQL: drop table "images")
    4. so in sqlite I typed: CREATE TABLE `images` ( ...> `id` INTEGER ...> );
    5. And then php artisan migrate:reset
    6. Now I'm happy again
    0 讨论(0)
  • 2021-02-02 11:54

    I ran into this aswell and the solution was different to all of the above. The reason it was failing was because the filename was still mentioned in the migrations table of the DB. Because there were no unique columns I couldn't remove it with PHPMyAdmin and had to tak the CLI route.

    Login to your server as root. Type the following:

    mysql -p database_name
    

    (it now prompts for your password. From here on out everything is preceded with mysql > which just means that you're in the Mysql environment.

    select * from migrations;
    

    Look for the migration file you removed and copy the name.

    delete from migrations where migration = '2015_07_21_000119_create_some_table';
    

    It should mention something about 1 row affected. Now verify that it's gone by typing the first command again:

    select * from migrations;
    

    If it's gone exit the Mysql environment by typing

    exit;
    

    Now try 'php artisan migrate:rollback' again and it should work like a charm :-)

    0 讨论(0)
  • 2021-02-02 11:55

    For me, the solution was that my class name inside the migration somehow started with a lowercase letter. When I changed the class name to be all upper case, then ran a composer dump-autoload, it ended up working for me. This is using Laravel 5.1, for what it's worth.

    0 讨论(0)
  • 2021-02-02 11:58

    There is an easier way.

    1. Recreate those delete migrations manually. artisan make:migration
    2. run artisan migrate:reset to rollback
    3. Delete those dummy migations files just created.
    4. run artisan migrate:refresh
    0 讨论(0)
  • 2021-02-02 12:02

    The actual solution is to use the correct naming for your translations. You still may need to do a

    composer dump-autoload

    The migration files must be as follows YYYY_MM_DD_000000_create_some_table.php and the class name inside must be

    class CreateSomeTable extends Migration{}

    0 讨论(0)
  • 2021-02-02 12:04

    I did like this: 1. Deleted row non exist migration from migrations table from database 2. And run the command php artisan migrate:refresh

    This helped to solve my problem.

    *all your data will deleted from database tables

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