【问题标题】:Symfony - Undefined type 'Doctrine\ORM\Mapping\EntitySymfony - 未定义类型 \'Doctrine\\ORM\\Mapping\\Entity
【发布时间】:2022-10-26 00:35:04
【问题描述】:

创建实体后,我在主题中遇到了许多与此类似的错误。不知道为什么因为使用标签似乎是正确的。使用 symfony 6.1。

这是我的模型: `

namespace App\Entity;

use App\Repository\MovieRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: MovieRepository::class)]
class Movie
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;

} `

【问题讨论】:

  • 似乎你解决了但你应该编辑你的问题并添加你得到的相关错误的所有堆栈跟踪。

标签: php symfony orm doctrine


【解决方案1】:

而不是这个

use DoctrineORMMapping as ORM;

#[ORMEntity(repositoryClass: MovieRepository::class)]
class Movie
{
#[ORMId]
#[ORMGeneratedValue]
#[ORMColumn(type: 'integer')]
private $id;

试试看

use DoctrineORMMappingColumn;
use DoctrineORMMappingEntity;
use DoctrineORMMappingGeneratedValue;
use DoctrineORMMappingId;

#[Entity(repositoryClass: MovieRepository::class)]
class Movie
{
    #[Id, GeneratedValue, Column(type: 'integer')]
    private int $id;

【讨论】:

  • 这行得通。但是这个模型是 symfony 自动创建的。有没有办法改变创建模型的方式?
【解决方案2】:

使用可视化代码编辑器,我打开另一个项目并重新打开当前项目, 错误消失...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-11
    • 2014-01-08
    • 2018-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多