我有以下实体:
/**
* Acme\DemoBundle\Entity\Book
*
* @ORM\Table(name="book")
* @ORM\Entity(repositoryClass="Acme\DemoBundle\Repository\BookRepository")
* @ORM\HasLifecycleCallbacks
* @UniqueEntity(fields="publickey", groups={"publickey"})
*/
class P1guestlistentry {
/**
* @var P1guestlistentrystatistic
*
* @ORM\OneToOne(targetEntity="P1guestlistentrystatistic", orphanRemoval=true, cascade={"all"}, fetch="EAGER")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="fkstatistic", referencedColumnName="pkId", nullable=false)
* })
*/
private $fkstatistic;
当我尝试删除像这里这样的对象时:
$this->getEntityManager()->getConnection()->beginTransaction();
try{
$book = $this->getEntityManager()->getRepository('AchmeDemoBundle:Book')->find(3928);
$this->getEntityManager()->remove($book);
$this->getEntityManager()->flush();
$this->getEntityManager()->getConnection()->commit();
}catch(Exception $e){
$this->getEntityManager()->getConnection()->rollBack();
echo $e->getMessage();
}
exit;
我可以做任何我想做的事,我收到以下错误:
执行“DELETE FROM WHERE pkId = ?”时发生异常 带参数 {"1":3928}: SQLSTATE[23000]: 完整性约束违规:1451 无法删除或更新父行:外键约束失败(
p1
.book
, CONSTRAINTFK_F51A442F78734022
FOREIGN KEY (fkstatistic
) REFERENCESbookstatistic
(pkId
))
有人知道我做错了什么吗?我尝试了很多方法,但没有任何帮助。