Doctrine \ DBAL \ Schema \ SchemaException - 表'clients'上没有名为'brand_id'的列

时间:2015-02-26 17:44:03

标签: php mysql symfony doctrine-orm

我正在设置一个Symfony2应用程序,并尝试使用Doctrine迁移。在这个特定的例子中,我正在尝试为我刚刚创建的实体,客户端添加一个新表,客户端。此表目前在数据库中不存在任何形式。

当我运行php app / console doctrine:migrations:diff时,我收到以下错误:

[Doctrine\DBAL\Schema\SchemaException]                       
There is no column with name 'brand_id' on table 'clients'

当然没有该名称的列,该表尚不存在!

Doctrine是否应该认识到没有表并创建它?作为参考,这是我的实体:

<?php

namespace RandomBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Client
 *
 * @ORM\Table(name="clients", indexes={@ORM\Index(name="brand_id", columns={"brand_id"})})
 * @ORM\Entity
 * @ORM\HasLifecycleCallbacks
 */
class Client
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=255, nullable=false)
     */
    private $name;

    /**
     * @var \RandomBundle\Entity\Brand
     *
     * @ORM\ManyToOne(targetEntity="RandomBundle\Entity\Brand")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="brand_id", referencedColumnName="id")
     * })
     */
    private $brand;

    /**
     * @var \RandomBundle\Entity\Project
     *
     * @ORM\OneToMany(targetEntity="RandomBundle\Entity\Project", mappedBy="client")
     */
    private $projects;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="updated_at", type="datetime", nullable=false)
     */
    private $updatedAt;
    /**
     * Constructor
     */
    public function __construct()
    {
        $this->projects = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set name
     *
     * @param string $name
     * @return Client
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Set updatedAt
     *
     * @param \DateTime $updatedAt
     * @return Client
     */
    public function setUpdatedAt($updatedAt)
    {
        $this->updatedAt = $updatedAt;

        return $this;
    }

    /**
     * Get updatedAt
     *
     * @return \DateTime 
     */
    public function getUpdatedAt()
    {
        return $this->updatedAt;
    }

    /**
     * Set brand
     *
     * @param \Ripplr3\RipplrBundle\Entity\Brand $brand
     * @return Client
     */
    public function setBrand(\RandomBundle\Entity\Brand $brand = null)
    {
        $this->brand = $brand;

        return $this;
    }

    /**
     * Get brand
     *
     * @return \RandomBundle\Entity\Brand 
     */
    public function getBrand()
    {
        return $this->brand;
    }

    /**
     * Add projects
     *
     * @param \RandomBundle\Entity\Project $projects
     * @return Client
     */
    public function addProject(\RandomBundle\Entity\Project $projects)
    {
        $this->projects[] = $projects;

        return $this;
    }

    /**
     * Remove projects
     *
     * @param \RandomBundle\Entity\Project $projects
     */
    public function removeProject(\RandomBundle\Entity\Project $projects)
    {
        $this->projects->removeElement($projects);
    }

    /**
     * Get projects
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getProjects()
    {
        return $this->projects;
    }
}

1 个答案:

答案 0 :(得分:4)

我能看到的唯一一点是索引声明

 * @ORM\Table(name="clients", indexes={@ORM\Index(name="brand_id", columns={"brand_id"})})

我不知道它是否在创建表格之前尝试创建索引。
尝试删除它以查看问题是否仍然存在