【发布时间】: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