我正在设置一个Symfony2应用程序,并尝试使用Doctrine迁移。在这个特定的实例中,我试图为我刚刚创建的实体客户端添加一个新的表客户端。该表目前在数据库中不存在任何形式。
当我运行php-app/console原则:migrations:diff时,我得到以下错误:
[DoctrineDBALSchemaSchemaException]
There is no column with name 'brand_id' on table 'clients'
当然,没有具有该名称的列,表还不存在!
难道教义不应该承认没有桌子并创造它吗?作为参考,这里是我的实体:
<?php
namespace RandomBundleEntity;
use DoctrineORMMapping as ORM;
/**
* Client
*
* @ORMTable(name="clients", indexes={@ORMIndex(name="brand_id", columns={"brand_id"})})
* @ORMEntity
* @ORMHasLifecycleCallbacks
*/
class Client
{
/**
* @var integer
*
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORMColumn(name="name", type="string", length=255, nullable=false)
*/
private $name;
/**
* @var RandomBundleEntityBrand
*
* @ORMManyToOne(targetEntity="RandomBundleEntityBrand")
* @ORMJoinColumns({
* @ORMJoinColumn(name="brand_id", referencedColumnName="id")
* })
*/
private $brand;
/**
* @var RandomBundleEntityProject
*
* @ORMOneToMany(targetEntity="RandomBundleEntityProject", mappedBy="client")
*/
private $projects;
/**
* @var DateTime
*
* @ORMColumn(name="updated_at", type="datetime", nullable=false)
*/
private $updatedAt;
/**
* Constructor
*/
public function __construct()
{
$this->projects = new DoctrineCommonCollectionsArrayCollection();
}
/**
* 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 Ripplr3RipplrBundleEntityBrand $brand
* @return Client
*/
public function setBrand(RandomBundleEntityBrand $brand = null)
{
$this->brand = $brand;
return $this;
}
/**
* Get brand
*
* @return RandomBundleEntityBrand
*/
public function getBrand()
{
return $this->brand;
}
/**
* Add projects
*
* @param RandomBundleEntityProject $projects
* @return Client
*/
public function addProject(RandomBundleEntityProject $projects)
{
$this->projects[] = $projects;
return $this;
}
/**
* Remove projects
*
* @param RandomBundleEntityProject $projects
*/
public function removeProject(RandomBundleEntityProject $projects)
{
$this->projects->removeElement($projects);
}
/**
* Get projects
*
* @return DoctrineCommonCollectionsCollection
*/
public function getProjects()
{
return $this->projects;
}
}
我能看到的唯一点是索引声明
* @ORMTable(name="clients", indexes={@ORMIndex(name="brand_id", columns={"brand_id"})})
我不知道它是否试图在创建表之前创建索引
尝试删除它以查看问题是否仍然存在