Doctrine Composite Keys Throwing Error

2019-08-13 03:28发布

I am trying to update my schema in doctrine using:

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

But I am getting the error message:

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

The events entity looks like this:

<?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;
    }

}

According to documentation, composite keys are natively supported. http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/tutorials/composite-primary-keys.html What am I doing wrong?

1条回答
兄弟一词,经得起流年.
2楼-- · 2019-08-13 04:17

From the docs:

Every entity with a composite key cannot use an id generator other than “ASSIGNED”. That means the ID fields have to have their values set before you call EntityManager#persist($entity).

So remove @GeneratedValue(strategy="AUTO").

查看更多
登录 后发表回答