No identifier/primary key specified for Entity (...) Every Entity must have and identifier/primary key
32,848
Solution 1
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;
Solution 2
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: .......
Author by
Admin
Updated on July 31, 2020Comments
-
Admin almost 4 years
I have
Peticion
entity but something is missing because appears the following error:No identifier/primary key specified for Entity (...) Every Entity must have and identifier/primary key
This is the entity code:
<?php namespace Project\UsuarioBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * Peticion * * @ORM\Table(name="peticion") * @ORM\Entity */ class Peticion { /** * * @ORM\Id * @ORM\ManyToMany(targetEntity="Project\UsuarioBundle\Entity\Usuario", inversedBy="usuNick2") * @ORM\JoinTable(name="USUARIO", * joinColumns={@ORM\JoinColumn(name="USU_NICK_1", referencedColumnName="USU_NICK")}, * inverseJoinColumns={@ORM\JoinColumn(name="USU_NICK_2", referencedColumnName="USU_NICK")} * ) */ private $usuNick1; /** * * @ORM\Id * @ORM\ManyToMany(targetEntity="Project\UsuarioBundle\Entity\Usuario", mappedBy="usuNick1")) */ private $usuNick2; /** * @var \DateTime * * @ORM\Column(name="PET_FECHA", type="date", nullable=false) */ private $fecha;
-
Ryall almost 7 yearsThis is incorrect, Doctrine should work with compound IDs (multiple IDs) and the variable does not need to be
$id
-
Gogowitsch almost 3 yearsI found that the
@ORM\Column(type="integer")
is crucial. I am using Doctrine 2.7.