Search code examples
phpsymfonyfixturesnelmio-alicealice-fixtures

Couldn't generate random unique value for "value" in 128 tries


I am defining this fixture:

Clanmovil\PlatformBundle\Entity\Alias:
    alias_{1..500}:
        name (unique): Alias_<numberBetween(1, 500)>
        description: <text(150)>
        active: <boolean(31)>
        createdAt: <dateTimeThisYear()>
        updatedAt: <dateTimeThisYear()>

And I am getting this error at console:

[RuntimeException] Couldn't generate random unique value for Clanmovil\PlatformBundle\Entity\Alias: name in 128 tries.

I did a little research through this error on sources at bundle but isn't clear to me what the issue could be. What is wrong here? How do I act when I found a issue like this one?

If this help this is how the entity looks like:

namespace Clanmovil\PlatformBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Clanmovil\PlatformBundle\Model\IdentifierAutogeneratedTrait;
use Symfony\Component\Validator\Constraints as Assert;
use Gedmo\Timestampable\Traits\TimestampableEntity;

/**
 * @ORM\Entity
 * @ORM\Table(name="cm_alias",
 *      uniqueConstraints={@ORM\UniqueConstraint(name="name", columns={"name"})},
        indexes={@ORM\Index(name="fulltext_idx",
            columns={"name"},
            flags={"fulltext"})})
 * )
 */
class Alias
{
    use IdentifierAutogeneratedTrait;
    use TimestampableEntity;

    /**
     * @var string
     * @ORM\Column(type="string", length=150)
     * @Assert\NotBlank()
     */
    protected $name;

    /**
     * @var string
     * @ORM\Column(type="text", nullable=true)
     */
    protected $description;

    /**
     * @var bool
     * @ORM\Column(type="boolean")
     */
    protected $active = true;

    /**
     * @ORM\ManyToMany(targetEntity="Command", mappedBy="command_alias", cascade={"persist"})
     */
    protected $alias_command;


    /**
     * Set name.
     *
     * @param string $name
     * @return Alias
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name.
     *
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Set description.
     *
     * @param string $description
     *
     * @return Alias
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

    /**
     * Get description.
     *
     * @return string
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * Set active.
     *
     * @param bool $active
     *
     * @return Category
     */
    public function setActive($active)
    {
        $this->active = $active;

        return $this;
    }

    /**
     * Get active.
     *
     * @return bool
     */
    public function getActive()
    {
        return $this->active;
    }

    /**
     * Get command for alias
     *
     * @return string
     */
    public function getAliasCommand()
    {
        return $this->alias_command;
    }

    public function __toString()
    {
        return $this->name;
    }

}

Solution

  • I don't know if this is the best solution but so far I have the issue fixed by just increasing the qty for random numbers:

    name (unique): Alias_<numberBetween(1, 1000)>