Faker on Laravel 5.5 don't add values to databse

508 Views Asked by At

I don't know what is the problem with faker but it refused to add new rows in the database and show the message:

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))

while the code for the factory is this:

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

Is anyone else facing the same problem or i am the only one in the planet :P

1

There are 1 best solutions below

1
On

The most possible reason for the null value is, that your values aren't fillable. You Category Class should have a variable like:

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

detailed example: http://kaloraat.com/articles/generate-fake-data-using-faker-and-factory-in-laravel