[英]Single id is not allowed on composite primary key in entity AdminBundle\Entity\Comptable
I created a simple entity with primary key id
and when I try to generate my entity, I get this error:我创建了一个带有主键
id
的简单实体,当我尝试生成我的实体时,我收到了这个错误:
[Doctrine\ORM\Mapping\MappingException] Single id is not allowed on composite primary key in entity AdminBundle\Entity\Comptable
[Doctrine\ORM\Mapping\MappingException] 实体 AdminBundle\Entity\Comptable 中的复合主键不允许使用单个 id
Here is the entity that contains some fields and the id
value that I already created it in the database:这是包含一些字段的实体和我已经在数据库中创建的
id
值:
<?php
namespace AdminBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Comptable
*
* @ORM\Table(name="comptable")
* @ORM\Entity
*/
class Comptable
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var float
*
* @ORM\Column(name="salaire", type="float", precision=10, scale=0, nullable=true)
*/
private $salaire;
/**
* @var \AdminBundle\Entity\Personne
*
* @ORM\Id
* @ORM\GeneratedValue(strategy="NONE")
* @ORM\OneToOne(targetEntity="AdminBundle\Entity\Personne")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="Per_id", referencedColumnName="id")
* })
*/
private $per;
public function __toString()
{
return $this->per->getPrenom().' '.$this->per->getNom();}
/**
* Set id
*
* @param integer $id
*
* @return Comptable
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set salaire
*
* @param float $salaire
*
* @return Comptable
*/
public function setSalaire($salaire)
{
$this->salaire = $salaire;
return $this;
}
/**
* Get salaire
*
* @return float
*/
public function getSalaire()
{
return $this->salaire;
}
/**
* Set per
*
* @param \AdminBundle\Entity\Personne $per
*
* @return Comptable
*/
public function setPer(\AdminBundle\Entity\Personne $per)
{
$this->per = $per;
return $this;
}
/**
* Get per
*
* @return \AdminBundle\Entity\Personne
*/
public function getPer()
{`enter code here`
return $this->per;
}
}
Remove the "@ORM\Id" from the "private $per;".从“private $per;”中删除“@ORM\Id”。 Multicolumn composite identifiers are not supported.
不支持多列复合标识符。
/**
* @var \AdminBundle\Entity\Personne
*
* @ORM\Id <=== REMOVE THIS
* @ORM\GeneratedValue(strategy="NONE")
* @ORM\OneToOne(targetEntity="AdminBundle\Entity\Personne")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="Per_id", referencedColumnName="id")
* })
*/
private $per;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.