【问题标题】:Laravel - Seeding isn't refreshingLaravel - 播种不令人耳目一新
【发布时间】:2020-01-28 11:41:25
【问题描述】:

我正在尝试植入 orders 迁移文件,但是在使用命令时:php artisan migrate: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();
});

【问题讨论】:

  • 另外,是的,我已将它包含在我的数据库播种器中。
  • 您的播种机中是否有正确的导入:use Illuminate\Database\Seeder;。尝试运行 composer dump-autoload 以防万一。
  • 每次更改/添加数据库/种子文件夹中的内容时,您需要composer dump-autoload

标签: php laravel


【解决方案1】:

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

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

composer dump-autoload

解释:

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

【讨论】:

    猜你喜欢
    • 2020-05-02
    • 2018-10-11
    • 1970-01-01
    • 2014-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-23
    • 1970-01-01
    相关资源
    最近更新 更多