fzaninotto/Faker

Maximum retries of 10000 reached without finding a unique value

steven7mwesigwa opened this issue · 1 comments

  • DistrictFactory.php
<?php

/** @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
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")
  • Faker version
    "fzaninotto/faker": "^1.9.1",

  • PHP version
    PHP 7.3.9 (cli) (built: Aug 28 2019 09:28:48) ( ZTS MSVC15 (Visual C++ 2017) x64 )

  • Laravel version
    "laravel/framework": "^7.0",

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