gpt4 book ai didi

php - 无法在 128 次尝试中为 "value"生成随机唯一值

转载 作者:搜寻专家 更新时间:2023-10-31 21:04:49 27 4
gpt4 key购买 nike

我正在定义这个 fixture :

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

我在控制台收到这个错误:

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

我通过 bundle 源上的这个错误做了一些研究,但我不清楚问题可能是什么。这里有什么问题?发现此类问题时我该如何处理?

如果这有帮助,这就是实体的样子:

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;
}

}

最佳答案

我不知道这是否是最好的解决方案,但到目前为止,我通过增加随机数的数量解决了这个问题:

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

关于php - 无法在 128 次尝试中为 "value"生成随机唯一值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34403331/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com