fzaninotto / Faker

Faker is a PHP library that generates fake data for you
MIT License
26.8k stars 3.57k forks source link

Maximum retries of 10000 reached without finding a unique value #2043

Open steven7mwesigwa opened 3 years ago

steven7mwesigwa commented 3 years ago

/* @var \Illuminate\Database\Eloquent\Factory $factory / use App\Models\GeneralSetting\Location\District; use Faker\Generator as Faker;

$factory->define(District::class, function (Faker $faker) { return [ "district_name" => $faker->unique()->state ]; });


- Error log

```shell
Seeded:  ClientsTableSeeder (0.75 seconds)
Seeding: DistrictsTableSeeder

   OverflowException

  Maximum retries of 10000 reached without finding a unique value

  at C:\xampp\htdocs\api-epitome\epitomeapi\vendor\fzaninotto\faker\src\Faker\UniqueGenerator.php:51
    47|         do {
    48|             $res = call_user_func_array(array($this->generator, $name), $arguments);
    49|             $i++;
    50|             if ($i > $this->maxRetries) {
  > 51|                 throw new \OverflowException(sprintf('Maximum retries of %d reached without finding a unique value', $this->maxRetries));
    52|             }
    53|         } while (array_key_exists(serialize($res), $this->uniques[$name]));
    54|         $this->uniques[$name][serialize($res)]= null;
    55|

  1   C:\xampp\htdocs\api-epitome\epitomeapi\vendor\fzaninotto\faker\src\Faker\UniqueGenerator.php:32
      Faker\UniqueGenerator::__call("state", [])

  2   C:\xampp\htdocs\api-epitome\epitomeapi\database\factories\DistrictFactory.php:9
      Faker\UniqueGenerator::__get("state")
Guxinpei commented 3 years ago

Hi @steven7mwesigwa Please sure do not use it more than numbers of state, this will happen when every state already used.