Replies: 2 comments
-
It is possible to generate 10,000 random numbers between 1 and 50 and not successfully generate all unique numbers from 1-50. It could, for example, never randomly generate the number 42. Even after 10,000 attempts. You may need to keep a static variable of values and pop them off randomly instead. |
Beta Was this translation helpful? Give feedback.
-
@timacdonald I'm creating 50 records: And I believe that 50 executions of Is this the wrong way to use it? |
Beta Was this translation helpful? Give feedback.
-
Laravel Version
11.26.0
PHP Version
8.3.14
Database Driver & Version
8.0.36 - MySQL Community Server - GPL
Description
The seeder fails when
fake()->unique()
is used in a factory.Error message:
Maximum retries of 10000 reached without finding a unique value
I'm creating 50 records:
factory()->count(50)->create()
And generating unique numbers between 1 and 50:
fake()->unique()->numberBetween(1, 50)
So unique numbers cannot be exhausted.
According to this issue, I can use
fake()->unique(true)
.This will eliminate errors, but it will cause data to become non-unique and duplicates to be generated.
Steps To Reproduce
Beta Was this translation helpful? Give feedback.
All reactions