0

问题是修补匠没有将内容包装在字符串中

使用消息'SQLSTATE [HY000] 照亮/数据库/查询异常:一般错误:1364 字段'address_line_2'没有默认值(SQL:插入( 、、、、、、、、、Testname值( emitchell 、dariana66@ genderhotmail . com, Kendra Friesen, Ole Carter, Gennaro Hickle, Prof. Brandon Herman 博士, 2018-12-21 01:07:12, 2018-12-21 01:07:12))'mobile_phonealternate_phonestatusaddress_line_1updated_atcreated_at

如果我手动将引号添加到每个值,例如

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.'

它不会输出字符串值...

到底是怎么回事 ?

4

1 回答 1

0

不需要指定数据类型,只需要调用函数

'name' => $faker->sentence(),

于 2020-03-02T12:48:56.187 回答