duandao1931 2016-11-11 02:32
浏览 42

为什么学说拒绝我的外键约束?

I'm attempting to add a many-to-one relationship between fields in two doctrine entities. I have a facebook feed table, which lists facebook feeds and their corresponding facebook IDs, and I have a FbPageLikes entity, which is a table where I record rows of the number of likes for these facebook feeds over time.

I believe I have annotated correctly, yet I still see this error when attempting to migrate: General error: 1215 Cannot add foreign key constraint

Is there something wrong with my annotations? How can I debug this doctrine migration?

FbPageLikes entity:

 /**
 * @var $facebookId
 *
 * @ORM\ManyToOne(targetEntity="Feed", inversedBy="fbPageLikes")
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="facebook_id", referencedColumnName="facebookId", onDelete="CASCADE")
 * })
 */
private $facebookId;

Feed entity:

/**
 * @var integer
 *
 * @ORM\Column(name="facebookId", type="bigint", nullable=true)
 */
private $facebookId;

/**
 * @var \Doctrine\Common\Collections\Collection
 *
 * @ORM\OneToMany(targetEntity="FbPageLikes", mappedBy="facebookId", fetch="EXTRA_LAZY")
 */
private $fbPageLikes;
  • 写回答

1条回答 默认 最新

  • dsgm5631 2016-11-11 18:32
    关注

    The reason why this setup failed was because of the annotations on the FbPageLikes entity. The referencedColumnName field must refer the the primary key in the corresponding entity Feed. http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/annotations-reference.html#annref-joincolumn

    In my case, I had to set referencedColumnName to refer to the id column of the Feed entity, instead of to the facebookId column.

    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)