我有兩個實體。用戶和聯繫人。用戶和聯繫人具有相同的屬性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".
有誰知道哪種方式我應該改變我的註解,這將工作?謝謝!