我有两个实体。用户和联系人。用户和联系人具有相同的属性phone_number。如果它存在,我想要获得与用户对象的所有联系人。联系人表中存在相同的电话号码,但在用户表中不存在。Symfony一对一,单向关系
下面是联系人实体注释:
/**
* @ORM\OneToOne(targetEntity="Dlabs\ServiceBundle\Entity\User", mappedBy="contact")
* @ORM\JoinColumn(name="phone", referencedColumnName="phone_number", nullable=true)
*/
private $user;
当我更新我的架构,我得到以下错误:
[Doctrine\DBAL\DBALException] An exception occurred while executing 'ALTER TABLE contact ADD CONSTRAINT FK_83DFDFA4444F97DD FOREIGN KEY (phone) REFERENCES users (phone_number) NOT DEFERRABLE INITIALLY IMMEDIATE': SQLSTATE[23503]: Foreign key violation: 7 ERROR: insert or update on table "contact" violates foreign key constraint "fk_83dfdfa4444f97dd" DETAIL: Key (phone)=(+38640775xxx) is not present in table "users".
[PDOException] SQLSTATE[23503]: Foreign key violation: 7 ERROR: insert or update on table "contact" violates foreign key constraint "fk_83dfdfa4444f97dd" DETAIL: Key (phone)=(+38640775xxx) is not present in table "users".
有谁知道哪种方式我应该改变我的注解,这将工作?谢谢!