2013-01-31 79 views
1

SF2和Doctrine有一个奇怪的问题。当试图从app.php运行我的应用程序我得到这个:Symfony2 Docrtine - 每个实体都必须有一个标识符/主键 - 它有一个主键?

[2013-01-31 15:40:05] request.CRITICAL: Doctrine\ORM\Mapping\MappingException: No identifier/primary key specified for Entity 'ACME\MyBundle\Entity\MyEntity'. Every Entity must have an identifier/primary key. (uncaught exception) at /lib/Doctrine/ORM/Mapping/MappingException.php line 37 [] [] 

这似乎相当自我解释。但据我所看到的,我有我的实体主键:

我的实体:

/** 
* @ORM\Entity 
* @ORM\Table(name="milestone") 
*/ 
class MyEntity 
{ 

    /** 
    * @ORM\Id 
    * @ORM\Column(type="integer") 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    protected $id; 

    /** 
    * @ORM\Column(type="string") 
    * @Assert\NotBlank() 
    * @Assert\MinLength(2) 
    * @Assert\MaxLength(100) 
    */ 
    protected $title; 

    /** 
    * @ORM\Column(type="datetime") 
    * @Assert\NotBlank() 
    */ 
    protected $date; 
    //////ETC 

然后在phpMyAdmin:

 Action   Keyname Type Unique Packed Column Cardinality Collation Null Comment 
Edit Drop PRIMARY BTREE Yes No id 63 A 

我的主键。非空。

使用app_dev.php应用程序运行运行良好,我作为被抑制的错误假设。

回答

0

试着用这个。它正在为我工​​作

/** 
    * @var integer $id 
    * @ORM\Column(name="id", type="integer") 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    private $id; 
0

我会建议设置字段不能为空。

/** 
* @var integer 
* 
* @ORM\Column(name="id", type="integer", nullable=false) 
* @ORM\Id 
* @ORM\GeneratedValue(strategy="AUTO") 
*/ 
protected $id; 

在因为你有表的任何情况下,你可以使用学说的CLI这是很方便的随时生成你的实体地图。

php [path-to-doctrine]/doctrine orm:convert-mapping --filter="TableNameInCamelCase" --namespace="[your-entity-namespace]" --force --from-database annotation [destination-path-of-entities] 

甚至有一个用于生成获取者和设置者。

相关问题