douti0687 2014-01-22 17:34
浏览 53

使用Symfony控制台创建数据库表的问题

I'm trying to create the database tables using Symfony command's using the following line :

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.

  • 写回答

1条回答 默认 最新

  • dpzlz08480 2017-07-04 23:12
    关注

    Just check if the Ciudad Entity has an 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;
    //..
    
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100