Doctric复合键引发错误

时间:2016-03-15 17:14:32

标签: php symfony doctrine-orm doctrine

我正在尝试使用以下方式更新我的架构:

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我做错了什么?

1 个答案:

答案 0 :(得分:1)

来自文档:

  

具有复合键的每个实体都不能使用“ASSIGNED”以外的id生成器。这意味着在调用EntityManager#persist($ entity)之前,ID字段必须设置其值。

删除@GeneratedValue(strategy="AUTO")