【发布时间】:2011-12-01 15:46:27
【问题描述】:
我想保存已创建的表单,但出现错误。
我有 3 个实体:
class T {
/**
* @ORM\OneToOne(targetEntity="MyNameSpace\ProfileBundle\Entity\Person", cascade={"persist"})
*/
private $information;
}
class Person {
/**
* @ORM\OneToOne(targetEntity="MyNameSpace\MediaBundle\Entity\Document", cascade={"persist"}))
*/
private $photo_profile;
}
class Document
{
private $file;
}
当我用这段代码保存我的“T”类时:
public function createAction()
{
$entity = new T();
$request = $this->getRequest();
$form = $this->createForm(new TType(), $entity);
$form->bindRequest($request);
if ($form->isValid())
{
$em = $this->getDoctrine()->getEntityManager();
$em->persist($entity);
$em->flush();
}
}
我有这个错误:
SQLSTATE[23000]:完整性约束违规:1452 无法添加或更新子行:外键约束失败(
namespace.person,CONSTRAINTFK_3370D440809EFCB0FOREIGN KEY(photo_profile_id)参考Document(id))
任何帮助都会很酷
谢谢大家
这是我的代码:
/**
* Creates a new Tutor entity.
*/
public function createAction()
{
$entity = new T();
$person = new Person();
$document = new Document();
$person->setPhoto($document);
$entity->setInformation($person);
$request = $this->getRequest();
$form = $this->createForm(new TType(), $entity);
$form->bindRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getEntityManager();
$em->persist($entity->getInformation()->getPhoto());
$em->persist($entity->getInformation());
$em->flush();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('Index'));
}
我有这个错误:
SQLSTATE[23000]:完整性约束违规:1452 无法添加或更新子行:外键约束失败(
db.T,CONSTRAINTFK_58C6694C2EF03101FOREIGN KEY (information_id) REFERENCESPerson(id))
任何帮助都会很酷
谢谢
【问题讨论】:
标签: php symfony doctrine-orm mysql-error-1064