FakerPHP/Faker - Maximum retries of 10000 reached without finding a unique value

104 views Asked by At

https://fakerphp.github.io/#modifiers

There is a 1-1 relationship between Detail and Video.

This is my seeder of Video (I make 500 Videos):

Video::flushEventListeners();
Video::factory()->count(500)->create();

This is my factory of Detail (It is the only unique() I use in this factory):

$ids = Video::withTrashed()->select('id')->get()->pluck('id'); // They are 500

return [
    ...
    'video_id' => $this->faker->unique()->randomElement($ids)
];

Output:

OverflowException 

Maximum retries of 10000 reached without finding a unique value

Why does this problem arise if there are 500 different Videos values for also 500 Details?

I understand that there would be a problem if there were 100 Videos for 500 Details, but this is not the case

After the error, if I run only the Detail seeder it works, this is very rare:

php artisan db:seed --class=DetailSeeder
0

There are 0 answers