我正在使用symfony 4.2和ReactJS。我有一封带邮件的表格。这封邮件应该是唯一的。因此,我在Entity中包含一个UniqueEntity。
当我尝试使用该表单创建帐户时,就会出现以下问题,它会向我抛出错误500:"An error occurred","hydra:description":"An exception occurred while executing \u0027INSERT INTO app_users (id, username, email, is_active, firstname, lastname, api_link_key, facebook_id, facebook_picture_url) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)\u0027 with params XXXXXX : Unique violation: 7 ERROR: duplicate key value violates unique constraint \u0022uniq_c2502824f85e0677\u0022\nDETAIL: Key (username)=(XXXXXX) already exists." 所以我可能没有此错误500,因此表单中没有消息错误?还是应该将消息错误设置在某处?
在我的实体中,当我设置邮件字段时,我也将用户名字段设置为相同的值。UniqueEntity禁止在同一行的两个字段中具有相同的值?
我的实体:
* @ORM\Table(name="app_users")
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @UniqueEntity("email")
*/
class User implements UserInterface, \Serializable
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", length=254, unique=true)
* @Encrypted
*/
private $username;
/**
* @ORM\Column(type="string", length=255, unique=true)
* @Assert\Email()
* @Assert\NotBlank()
* @Encrypted
*/
private $email;
[...]
public function getEmail()
{
return $this->email;
}
public function setEmail($email): void
{
$this->email = $email;
$this->username = $email;
}
}
Qyouu