【发布时间】:2023-03-10 08:13:01
【问题描述】:
我使用 MySql 处理 Symfony2 和 Doctrine ORM。 当我尝试使用 uo 时:
php app/console doctrine:migration:diff
我有这个错误:
[Doctrine\DBAL\Schema\SchemaException]
The table with name 'blog.post' already exists.
我在 Post.php 中的代码(我使用注释)是:
namespace Blog\ModelBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Post
*
* @ORM\Table()
* @ORM\Entity
*/
class Post extends Timestampable
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=150)
* @Assert\NotBlank
*/
private $title;
/**
* @var string
*
* @ORM\Column(name="body", type="text")
* @Assert\NotBlank
*/
private $body;
/**
* @var Author
* @ORM\ManyToOne (targetEntity="Author", inversedBy="posts")
* @ORM\JoinColumn (name="author_id", referencedColumnName="id", nullable=false)
* @Assert\NotBlank
*/
private $author;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* @param string $title
* @return Post
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set body
*
* @param string $body
* @return Post
*/
public function setBody($body)
{
$this->body = $body;
return $this;
}
/**
* Get body
*
* @return string
*/
public function getBody()
{
return $this->body;
}
/**
* Set author
*
* @param \Blog\ModelBundle\Entity\Author $author
* @return Post
*/
public function setAuthor(Author $author)
{
$this->author = $author;
return $this;
}
/**
* Get author
*
* @return \Blog\ModelBundle\Entity\Author
*/
public function getAuthor()
{
return $this->author;
}
}
我尝试定义 * @ORM\Table(name="Post")。
你能帮我解决这种类型的错误吗? 对不起我的英语不好。
【问题讨论】:
-
您有来自另一个实体映射的冲突。它可以是
JoinTable或其他实体。 -
我只有一个实体 - 作者,我有: /** * @var ArrayCollection * * @ORM\OneToMany(targetEntity="Post", mappedBy="author", cascade={"删除"}) */ 私人 $posts;
标签: symfony doctrine-orm