I'm trying to create the database tables using Symfony command's using the following line :
我正在尝试使用Symfony命令使用以下行创建数据库表:
php app/console doctrine:schema:create
I obtain the following error :
我收到以下错误:
[Doctrine\ORM\Mapping\MappingException]
No identifier/primary key specified for Entity "Cupon\CiudadBundle\Entity\Ciudad". Every Entity must have an identifier/primary key.
And it's the above class :
它是上面的类:
namespace Cupon\TiendaBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/** @ORM\Entity */
class Tienda
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
protected $id;
/** @ORM\ManyToOne(targetEntity="Cupon\CiudadBundle\Entity\Ciudad") */
protected $ciudad;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set ciudad
*
* @param \Cupon\CiudadBundle\Entity\Ciudad $ciudad
* @return Tienda
*/
public function setCiudad(\Cupon\CiudadBundle\Entity\Ciudad $ciudad = null)
{
$this->ciudad = $ciudad;
return $this;
}
/**
* Get ciudad
*
* @return \Cupon\CiudadBundle\Entity\Ciudad
*/
public function getCiudad()
{
return $this->ciudad;
}
public function __toString()
{
return $this->getNombre();
}
}
I don't understand whats really happen, because I put the ID for the class. Any help is appreciated.
我不明白什么事情真的发生了,因为我把这个ID放在了班上。任何帮助表示赞赏。
1 个解决方案
#1
0
Just check if the Ciudad Entity has an id
只需检查Ciudad Entity是否有id
You should include the following annotations for example:
您应该包括以下注释,例如:
namespace Cupon\TiendaBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/** @ORM\Entity */
class Ciudad
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
protected $id;
//..
#1
0
Just check if the Ciudad Entity has an id
只需检查Ciudad Entity是否有id
You should include the following annotations for example:
您应该包括以下注释,例如:
namespace Cupon\TiendaBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/** @ORM\Entity */
class Ciudad
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
protected $id;
//..