主义组合键投掷的错误

问题描述:

我试图用更新我的教义模式:主义组合键投掷的错误

php vendor/bin/doctrine orm:schema-tool:update 

但我收到错误消息:

[Doctrine\ORM\Mapping\MappingException]          
    Single id is not allowed on composite primary key in entity entities\Events 

事件实体看起来是这样的:

<?php 
// entities/Events.php 

namespace entities; 

use Entities\Enities; 
use Doctrine\ORM\Mapping; 
use Doctrine\ORM\Mapping\Table; 

/** 
* @Entity 
* @Table(name="development.events") 
**/ 
class Events extends Entities { 
    /** 
    * @var integer 
    * 
    * @Id 
    * @Column(name="id", type="integer") 
    * @GeneratedValue(strategy="AUTO") 
    */ 
    protected $event_id; 

    /** 
    * @var integer 
    * 
    * @Id 
    * @Column(name="app_id", type="integer") 
    */ 
    protected $app_id = 0; 

    /** 
    * @var string 
    * @Column(type="string", length=64) 
    */ 
    protected $post_title; 

    public function __construct($event, $app){ 
     $this->event_id = $event; 
     $this->app_id= $app; 
    } 

} 

根据文档,本机支持组合键。 http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/tutorials/composite-primary-keys.html我做错了什么?

从文档:

与复合键不能使用除“分配”,其他的ID生成每个实体。这意味着在调用EntityManager#persist($ entity)之前,ID字段必须设置其值。

因此删除@GeneratedValue(strategy="AUTO")

+0

它的工作,但这是否意味着,为了这个价值,我必须以编程方式,伟大和ID或UUID而不是让数据库创建自动递增值? –

+0

是的,或者你可以使用[#identity-through-foreign-entities](http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/tutorials/composite-primary-keys.html#身份通过外国实体),但我真的不明白你的用例是什么,你想达到什么目的?不推荐使用复合键,你应该尽可能避免使用。 – 1ed