In my Laravel 5.8 app I create factory with defintion in database/factories/HostelReviewFactory.php :
$factory->define(App\HostelReview::class, function (Faker $faker, $parentParams) {
$flag_status= 'N';
if( rand(1,4) == 1) {
$flag_status= 'R';
}
$parent_hostel_id= $parentParams['parent_hostel_id'];
return [
'hostel_id' => $parent_hostel_id,
'email_inquiried' => $faker->safeEmail,
'full_name' => $faker->name,
'status' => 'A',
'flag_status' => $flag_status,
'review' => $faker->text,
'stars_rating_type_id' => rand(1,5),
'created_at' => $faker->dateTimeBetween( '-2 years', 'now', config('app.timezone') ) ,
];
});
and running it from seeder database/seeds/HostelReviewsTableSeeder.php :
factory(App\HostelReview::class, 10)->create([ 'parent_hostel_id' => 30 ]);
I got error :
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'parent_hostel_id' in 'field list' (SQL: insert into `ad_hostel_reviews` (`hostel_id`, `email_inquiried`, `full_name`, `status`, `flag_status`, `review`, `stars_rating_type_id`, `created_at`, `parent_hostel_id`) values (30, beer.ozella@example.com, Jamel Konopelski, A, N, Quis mollitia voluptas occaecati corrupti ut. Commodi dolorem delectus architecto nesciunt voluptatem quos. Itaque natus adipisci dicta impedit sint. Alias inventore accusantium ea., 3, 2018-02-13 01:18:34, 30))
looks like all values from $parentParams are added to fields list of target table, and I do not need it, as $parentParams are just parameters I want to set to factory. What is wrong ?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire