Laravel-种子没有刷新

时间:2019-09-28 12:54:25

标签: php laravel

我正在尝试播种 orders 迁移文件,但是使用以下命令后: php artisan migration:refresh --seed ,将返回以下错误

ReflectionException  : Class OrdersTableSeeder does not exist

我很笨,或者Laravel坏了。

种子:

class OrdersTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        DB::table('orders')->insert([
            'user_id' => 1,
            'product_id' => 1,
            'quantity' => 10,
            'updated_at' => DB::raw('CURRENT_TIMESTAMP')
        ]);

        DB::table('orders')->insert([
            'user_id' => 1,
            'product_id' => 2,
            'quantity' => 5,
            'updated_at' => DB::raw('CURRENT_TIMESTAMP')
        ]);
    }
}

迁移:

Schema::create('orders', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->integer('user_id'); //fk
    $table->integer('product_id'); //fk
    $table->integer('quantity');
    $table->timestamps();
});

1 个答案:

答案 0 :(得分:1)

类不存在的错误似乎是Laravel无法找到名为 OrdersTableSeeder 的类。

我希望使用下面的命令有帮助。

composer dump-autoload

说明:

Why do I have to run "composer dump-autoload" command to make migrations work in laravel?