如何用原则解决方案更新错误?

问题描述 投票:0回答:1

我在使用Symfony 4.3.4制作的一个非常简单的应用程序上遇到问题

我刚刚更新了一个实体,并尝试使用“ doctrine:schema:update --force”更新我的数据库,但是这里有一个问题:An exception occurred while executing 'ALTER TABLE lead ADD content LONGTEXT DEFAULT NULL'

第二条消息:Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'lead ADD content LONGTEXT DEFAULT NULL' at line 1

我试图更改“ content”属性的名称(这是我添加的名称),但这没有用。有人知道为什么会这样吗?

这里是我的主管实体:

 <?php

 namespace App\Entity;

 use Doctrine\Common\Collections\ArrayCollection;
 use Doctrine\Common\Collections\Collection;
 use Doctrine\ORM\Mapping as ORM;

 /**
  * @ORM\Entity(repositoryClass="App\Repository\LeadRepository")
  */
 class Lead
 {
/**
 * @ORM\Id()
 * @ORM\GeneratedValue()
 * @ORM\Column(type="integer")
 */
private $id;

/**
 * @ORM\Column(type="datetime")
 */
private $createdAt;

/**
 * @ORM\Column(type="boolean")
 */
private $isAuth = false;

/**
 * @ORM\ManyToOne(targetEntity="App\Entity\Formation", inversedBy="leads")
 * @ORM\JoinColumn(nullable=false)
 */
private $formation;

/**
 * @ORM\Column(type="text", nullable=true)
 */
private $content;

public function __construct()
{
    $this->createdAt = new \DateTime();
}

public function getId(): ?int
{
    return $this->id;
}

public function getCreatedAt(): ?\DateTimeInterface
{
    return $this->createdAt;
}

public function setCreatedAt(\DateTimeInterface $createdAt): self
{
    $this->createdAt = $createdAt;

    return $this;
}

public function getIsAuth(): ?bool
{
    return $this->isAuth;
}

public function setIsAuth(bool $isAuth): self
{
    $this->isAuth = $isAuth;

    return $this;
}

public function getFormation(): ?Formation
{
    return $this->formation;
}

public function setFormation(?Formation $formation): self
{
    $this->formation = $formation;

    return $this;
}

public function getContent(): ?string
{
    return $this->content;
}

public function setContent(?string $content): self
{
    $this->content = $content;

    return $this;
}

}

database symfony doctrine
1个回答
0
投票

“ lead”似乎是MySQL的保留关键字,因此您需要使用反引号将其转义,如下所示:

/**
 * @ORM\Entity(repositoryClass="App\Repository\LeadRepository")
 * @ORM\Table(name="`lead`")
 */

您还需要对其他用作字段名称的常用关键字(例如“ order”和“ sort”)进行此操作。

© www.soinside.com 2019 - 2024. All rights reserved.