主义组合键投掷错误 [英] Doctrine Composite Keys Throwing Error

查看:71
本文介绍了主义组合键投掷错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下方法更新学说中的模式:

I am trying to update my schema in doctrine using:

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 / zh-CN / latest / tutorials / composite-primary-keys.html 我在做什么错了?

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?

推荐答案

从文档中获取:


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

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).

因此删除 @GeneratedValue(strategy = AUTO)

这篇关于主义组合键投掷错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆