dtr32787
2013-07-26 07:17
浏览 77
已采纳

如何在'doctrine:generate:entity'命令中指定id选项?

I'm using doctrine:generate:entity command to generate entities. I want to use guid (string(32)) instead of integer as id type, but when I specify it like id:string(32) in --fields option I get following error:

[Doctrine\ORM\Mapping\MappingException]
Duplicate definition of column 'id' on entity 'Acme\DemoBundle\Entity\Test' in a field or discriminator column mapping.

What should I do to get it working?

@answer: As @loicfavory wrote in comment to his answer the only way is to extend Sensio\Bundle\GeneratorBundle\Generator\DoctrineEntityGenerator class where id options are set manually.

图片转代码服务由CSDN问答提供 功能建议

我正在使用 doctrine:generate:entity 命令来生成实体。 我想使用 guid string(32))而不是 integer 作为id类型,但是当我像 id一样指定它时: - fields 选项中的字符串(32)我收到以下错误:

  [Doctrine \ ORM \ Mapping \ MappingException] 
Duplicate 在字段或鉴别器列映射中实体'Acme \ DemoBundle \ Entity \ Test'上的列'id'的定义。
   
 
 

我应该怎么做才能让它工作 ?

@answer: 作为@loicfavory在评论中写道,唯一的方法是扩展 Sensio \ Bundle \ GeneratorBundle \ Generator \ DoctrineEntityGenerator 类,其中 id 选项是手动设置的。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doujiu3095 2013-07-26 07:31
    已采纳

    The Id is automatically generated by the DoctrineEntityGenerator with the integer type. I think that if you specify it with the --fields option, it duplicate the creation of the field.

    That's the error you got.

    Did you try to change the type manually in the entity class, after the command create it ?

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题