UniqueEntity 日期时间 Symfony4:"The field is not mapped by Doctrine, so it cannot be validated for uniqueness."

UniqueEntity datetime Symfony4 : "The field is not mapped by Doctrine, so it cannot be validated for uniqueness."

我正在尝试将 UniqueEntity 用于日期时间字段。当我将其与字符串字段或电子邮件一起使用时,一切正常。但是对于 datetime: "The field "date_one" 没有被 Doctrine 映射,所以不能验证它的唯一性。"

(...)
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;

/**
 * @ORM\Entity(repositoryClass="App\Repository\VisitRepository")
 * @UniqueEntity("date_one")
 */

(...)

/**
* @ORM\Column(name="date_one", type="datetime", unique=true)
* [$dateOne description]
* @Assert\DateTime
* @var string A "m/d/Y H:i:s" formatted value
* @Assert\Range(
*      min = "now"
* )
*/
protected $dateOne;

一个想法?

您是否尝试过 dateOne 而不是 date_one 作为 UniqueEntity 的字段?

所以,没关系:

(...)
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;

/**
 * @ORM\Entity(repositoryClass="App\Repository\VisitRepository")
 * @UniqueEntity(
 *     fields={"dateOne"},
 *     message="Cette date est déjà prise"
 * )
 */

(...)