gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 01:28:25 26 4
gpt4 key购买 nike

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

当我运行 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;
}
}

最佳答案

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

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

我不知道它是否试图在创建表之前创建索引..
尝试删除它,看看问题是否仍然存在

关于php - Doctrine\DBAL\Schema\SchemaException - 表 'brand_id' 上没有名称为 'clients' 的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28749227/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com