Symfony2:缺少分配的ID [英] Symfony2 : missing an assigned ID
问题描述
我有一个Place和一个Placetype实体.我的位置实体的id属性设置为AUTO:
I have a Place and a Placetype entity. My Place entity have his id attribute set to AUTO:
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
但是当我要保留一个对象时,出现以下错误:
But when I want to persist an object, I got the following error :
blabla \ Entity \ Place类型的实体缺少分配的ID.这该实体的标识符生成策略需要ID字段在调用EntityManager#persist()之前填充.如果你想自动生成的标识符,而您需要调整元数据映射.
Entity of type blabla\Entity\Place is missing an assigned ID. The identifier generation strategy for this entity requires the ID field to be populated before EntityManager#persist() is called. If you want automatically generated identifiers instead you need to adjust the metadata mapping accordingly.
您知道如何解决此问题吗?
Do you know how to fix this?
感谢您的帮助
推荐答案
它可以通过替换以下内容来实现:
It works by replacing this :
/**
* @var integer $uid
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
对此:
/**
* @var integer $uid
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
*/
private $id;
这篇关于Symfony2:缺少分配的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!