我試圖播種數據庫。在用戶示例之後,我創建了一個Emploi(Job)播種機,但出現錯誤。Laravel:播種數據庫時出錯(數組到字符串轉換)
種子文件
$factory->define(App\Emploi::class, function (Faker\Generator $faker) {
return [
'JOBURL' => $faker->name,
'SALARYMAX' => '$50,000',
'SALARYMIN' => '$40,000',
'SALARYTYPE' => 'annual',
'NAME' => $faker->words(5),
'POSITION' => $faker->words(4),
'JOBREF' => str_random(10),
'JOB_SUMMARY' => $faker->text,
'tweeted' => false,
'POSTDATE' => $faker->dateTime(),
'EXPIRYDATE' => $faker->dateTime(),
'slug' => str_random(10),
];
});
例外
[ErrorException]
Array to string conversion
輸出
[Illuminate\Database\QueryException]
Array to string conversion
(SQL: insert into `emplois`
(`JOBURL`, `SALARYMAX`,
`SALARYMIN`, `SALARYTYPE`, `NAME`, `POSITION`,
`JOBREF`,
`JOB_SUMMARY`,
`tweeted`, `
POSTDATE`, `EXPIRYDATE`, `slug`,
`updated_at`, `created_at`)
values
(Lawson Boyer II, $50,000,
$40,000, annual, rerum, voluptates,
LCw8d67S8w,
Nulla qui corporis sequi.
Eum nostrum culpa ut culpa velit.
Molestiae cumque doloremque et ex.,
0,
1972-11-09 12:00:07, 1997-10-04 09:08:17, 6FxxCHFus6,
2017-05-28 03:18:52, 2017-05-2 8 03:18:52)
)
databaseSeeder
factory(App\Emploi::class, 50)->create();
檢查'$ faker-> words()'的輸出。 –
@WesleyPeeters謝謝我有這個數組('leri','rednar','pratpu')。你能發表一個答案,以便我可以投票你的答案 –
你走了!祝你今天愉快! –