Doctrine orm 奇怪的级联行为学说2

Doctrine orm 奇怪的级联行为学说2,doctrine-orm,Doctrine Orm,我有两个实体 TB\Entity\UserProfile /** * @OneToMany(targetEntity="TB\Entity\ShopVideo", mappedBy="shop", * cascade={"persist", "remove"} * ) */ private $video; 及 TB\Entity\ShopVideo /** * @var UserProfile * * @ManyToOne(targetEntity="TB\Entity

我有两个实体

TB\Entity\UserProfile
/** 
 * @OneToMany(targetEntity="TB\Entity\ShopVideo", mappedBy="shop",
 * cascade={"persist", "remove"}
 * )
 */
private $video;    
及 TB\Entity\ShopVideo

/**
 * @var UserProfile
 *
 * @ManyToOne(targetEntity="TB\Entity\UserProfile")
 * @JoinColumns({
 *   @JoinColumn(name="shop", referencedColumnName="id")
 * })
 */
private $shop;
如果我创建一个UserProfile实例和一个ShopVideo实例

    $profile = new TB\Entity\UserProfile();
    $model = new TB\Entity\ShopVideo();

    $profile->getShopVideo()->add($model);
    $this->_em->persist($profile);
    $this->_em->flush();
我希望'shop'列中填充'UserProfile'的id(以及其他已经工作的模型)。。。但是我得到了错误(由于外键限制)

PDOException:SQLSTATE[23000]:完整性约束冲突:1048列“shop”不能为null

/Users/ABCD/work/TB/TB/library/Doctrine/DBAL/Statement.php:131
/Users/ABCD/work/TB/TB/library/Doctrine/ORM/Persisters/BasicEntityPersister.php:226
/Users/ABCD/work/TB/TB/library/Doctrine/ORM/UnitOfWork.php:698
/Users/ABCD/work/TB/TB/library/Doctrine/ORM/UnitOfWork.php:280
/Users/ABCD/work/TB/TB/library/Doctrine/ORM/EntityManager.php:328

我只是不明白为什么ShopVideo没有层叠操作并用USerProfile的id设置shop列?任何帮助都将不胜感激

在@manytone上尝试添加inversedBy=“video”。这可能解决这个问题,也可能解决不了这个问题,但在双向关联的情况下,这是一个必需的属性