我有兩個模型:Entity \ Announcement.php和Entity \ Submission.php。完整性約束違規:1048'announcement_id'列不能爲空
在我的實體\ Submission.php,我這樣定義與實體\ Announcement.php的關係:
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Announcement")
* @ORM\JoinColumn(nullable=false)
*/
protected $announcement;
當用戶訪問一個通知他們必須提交建議書的能力。
在我的控制,我這樣定義的提交動作:
/**
* @Route("/submit/{id}", name="submissions_new")
*/
public function submitAction(Request $request, Announcement $id)
{
$submission = new Submission();
$submission->setAnnouncement($id);
$form = $this->createForm(SubmissionType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$submission = $form->getData();
$em->persist($submission);
$em->flush();
return $this->redirectToRoute('announcements_list');
}
return $this->render(':submissions:submit.html.twig', [
'form' => $form->createView(),
'announcement' => $id->getId()
]);
}
當我試圖從我的路線提交/提交/ 73c67a07-744d-11e7-9670-08d40c1d4f7f,我得到這個錯誤:
An exception occurred while executing 'INSERT INTO reports (id, title, date, author, description, announcement_id) VALUES (?, ?, ?, ?, ?, ?)' with params ["ff28c231-7843-11e7-a72b-08d40c1d4f7f", "aaa", "2012-01-01 00:00:00", "aaa", "aaa", null]:
Integrity constraint violation: 1048 Column 'announcement_id' cannot be null
當我評論這條線在我的控制器:
//$submission = $form->getData();
,並嘗試再次提交,我得到這個錯誤:
An exception occurred while executing 'INSERT INTO reports (id, title, date, author, description, announcement_id) VALUES (?, ?, ?, ?, ?, ?)' with params ["d12ea15b-7843-11e7-a72b-08d40c1d4f7f", null, null, null, null, "73c67a07-744d-11e7-9670-08d40c1d4f7f"]:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'title' cannot be null
你能否幫忙提交所有的字段?
謝謝