问题是修补匠没有将内容包装在字符串中
带有消息'SQLSTATE [HY000]的Illuminate / Database / QueryException: 常规错误:1364字段“ address_line_2”没有默认值 值(SQL:插入
Test
(name
,gender
,mobile_phone
,alternate_phone
,status
,address_line_1
,updated_at
,created_at
)值(emitchell,dariana66 @ hotmail.com,Kendra Friesen,Ole Carter,Gennaro Hickle,Brandon Herman教授, 2018-12-21 01:07:12,2018-12-21 01:07:12))'
如果我将引号手动添加到每个值,例如
values ('emitchell', 'dariana66@hotmail.com', 'Kendra
Friesen', 'Ole Carter', 'Gennaro Hickle', 'Prof. Brandon Herman PhD',
'2018-12-21 01:07:12', '2018-12-21 01:07:12')
有效
我如何才能使修补匠用引号引起的随机内容产生?
我什至使用(string)
$factory->define(App\Test::class, function (Faker $faker) {
return [
'name' => (string)$faker->sentence(),
'gender' => (string)$faker->sentence(),
'mobile_phone' => (string)$faker->sentence(),
'alternate_phone' => (string)$faker->sentence(),
'status' => (string)$faker->sentence(),
'address_line_1' => (string)$faker->sentence(),
'address_line_2' => (string)$faker->sentence(),
'town_city' => (string)$faker->sentence(),
'postscode' => (string)$faker->sentence(),
'notes' => (string)$faker->sentence()
];
});
或github页面上的示例
'name' => $faker-> sentence($nbWords = 6, $variableNbWords = true), // 'Sit vitae voluptas sint non voluptates.'
它不会输出字符串值...
怎么回事?
答案 0 :(得分:0)
您无需指定数据类型,只需调用函数
'name'=> $ faker-> sentence(),