No identifier/primary key specified for Entity (…) Every Entity must have and identifier/primary key

懵懂的女人 提交于 2019-12-04 23:30:33

You need to specify id field and remove other @ORM\Id annotations. Identifiers / Primary Keys at doctrine documentation.

Every entity class needs an identifier/primary key. You designate the field that serves as the identifier with the @Id marker annotation.

/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;
Игорь Казубек

The solution is to add the id field to the EntityName.orm.yml id: true For example:

AppBundle \ Entity \ Supplier:
   type: entity
   table: sylius_supplier
   fields:
     id:
       type: integer
       id: true
       generator:
         strategy: AUTO
     name: .......

In my case, what happened was this:

I create the entity file, and put it in the entity directory, with the database schema.

But here is the thing, I also created created a YML file for the entity and put it inside Resources/config/doctrine, without a schema. Symfony was looking for the schema inside YML. Once I removed the YML file, the schema in my entity file worked just fine.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!