0

我不知道 faker 有什么问题,但它拒绝在数据库中添加新行并显示消息:

Illuminate\Database\QueryException with message 'SQLSTATE[HY000]: General error: 1364 Field 'title' doesn't have a default value (SQL: insert into 'categories' ('updated_at', 'created_at') values (2017-09-14 16:17:43, 2017-09-14 16:17:43))

而工厂的代码是这样的:

$factory->define(App\Category::class, function (Faker $faker) {
    return [
        'title' => $faker->sentence(4),
        'description' => $faker->text(300),
    ];
});

是否还有其他人面临同样的问题,或者我是这个星球上唯一的人:P

4

1 回答 1

1

空值的最可能原因是您的值不可填充。您的类别类应该有一个变量,如:

protected $fillable = ["title", "description"];

详细示例: http: //kaloraat.com/articles/generate-fake-data-using-faker-and-factory-in-laravel

于 2017-09-14T16:55:35.610 回答