每當我試圖刪除/刪除實體的「候選」我得到這個錯誤:學說ORM錯誤:外鍵約束失敗
An exception occurred while executing 'DELETE FROM candidate WHERE id = ?' with params {"1":3}: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`ima`.`result`, CONSTRAINT `result_ibfk_2` FOREIGN KEY (`test_id`) REFERENCES `Test` (`id`))
下面是所涉及的學說ORM實體的關係:
實體:候選
/**
* @OneToMany(targetEntity="Test", mappedBy="candidate",
* cascade={"persist"})
*
* @var ArrayCollection
*/
private $tests;
實體:測試
/**
* @ManyToOne(targetEntity="Candidate", inversedBy="tests")
* @JoinColumn(name="candidate_id", referencedColumnName="id", onDelete="cascade")
*/
private $candidate;
/**
* @OneToMany(targetEntity="Answer", mappedBy="test", cascade={"persist", "remove"})
* @var ArrayCollection
*/
private $answers;
/**
* @OneToMany(targetEntity="Result", mappedBy="test", cascade={"persist"})
* @var ArrayCollection
*/
private $results;
實體:答案
/**
* @ManyToOne(targetEntity="Test", inversedBy="answers")
* @JoinColumn(name="test_id", referencedColumnName="id")
*/
private $test;
實體:結果
/**
* @ManyToOne(targetEntity="Test", inversedBy="results")
*/
protected $test;
我在做什麼錯?請幫忙。謝謝。