Reputation: 341
When I use Factories in a test class in phpunit, field value doesn't insert into database. It returns error
General error: 1364 Field 'name' doesn't have a default value (SQL: insert
into province() values ())
My factory is: use Faker\Generator as Faker;
$factory->define(\App\Provinces::class, function (Faker $faker) {
return [
'name' => $faker->name
];
});
Upvotes: 1
Views: 707
Reputation: 341
I solved the problem.
This problem occurred because in the __construct method of Provinces
model I missed this line:
parent::__construct($attributes);
So, my constructor should be like this:
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
}
Upvotes: 4