每个实体都必须有一个标识符/主键

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

有一个 symfony 项目,从 5.1 更新到 6.4 LTS,并将原则更新到 3.0.0。

将此实体从注释更新为 PHP8 属性:

`

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: "App\Repository\SottocontiUtentiRepository")]
class SottocontiUtenti
{
    #[ORM\Id]
    #[Column(type: "integer")]
    private int $utente_id;

    #[ORM\Id]
    #[Column(type: "integer")]
    private int $pratica_id;

    #[ORM\Id]
    #[Column(type: "integer")]
    private int $finanziamento_id;

    #[Column(type: "string")]
    private $nome;

    #[Column(type: "string")]
    private $cognome;

    // Ripristino della relazione
    #[ORM\ORM\Id()]
    #[ManyToOne(targetEntity: Sottoconti::class, inversedBy: "utenti")]
    #[JoinColumn(name: "sottoconto_id", referencedColumnName: "sottoconto_id", nullable: true)]
    private ?Sottoconti $sottoconto_id;  // Nota l'utilizzo del tipo per Sottoconti

    #[Column(type: "float", nullable: true)]
    private $importo_deliberato;

    #[Column(type: "string", nullable: true)]
    private $rientro;


    public function getUtenteId(): ?int
    {
        return $this->utente_id;
    }

    public function setUtenteId(int $utente_id): self
    {
        $this->utente_id = $utente_id;

        return $this;
    }

    public function getSottocontoId(): ?Sottoconti
    {
        return $this->sottoconto_id;
    }

    public function setSottocontoId(?Sottoconti $sottoconto_id): self
    {
        $this->sottoconto_id = $sottoconto_id;

        return $this;
    }

    public function getPraticaId(): ?int
    {
        return $this->pratica_id;
    }

    public function setPraticaId(int $pratica_id): self
    {
        $this->pratica_id = $pratica_id;

        return $this;
    }

    public function getFinanziamentoId(): ?int
    {
        return $this->finanziamento_id;
    }

    public function setFinanziamentoId(int $finanziamento_id): self
    {
        $this->finanziamento_id = $finanziamento_id;

        return $this;
    }

    public function getImportoDeliberato(): ?float
    {
        return $this->importo_deliberato;
    }

    public function setImportoDeliberato(?float $importo_deliberato): self
    {
        $this->importo_deliberato = $importo_deliberato;

        return $this;
    }

    /**
     * @return mixed
     */
    public function getRientro()
    {
        return $this->rientro;
    }

    /**
     * @param mixed $rientro
     */
    public function setRientro($rientro): void
    {
        $this->rientro = $rientro;
    }
}

` 出现此错误: 没有为实体“App\Entity\SottocontiUtenti”指定标识符/主键。每个实体都必须有一个标识符/主键。

尝试用 Google 搜索并询问 Gemini ADV 或 ChatGPT。 什么都不起作用。 也尝试过这种方式: https://www.doctrine-project.org/projects/doctrine-orm/en/3.0/tutorials/composite-primary-keys.html#composite-and-foreign-keys-as-primary-key

但仍然遇到同样的错误。

有什么建议吗?

非常感谢, 贾科莫。

doctrine-orm doctrine symfony6
1个回答
0
投票

看起来您缺少

importo_deliberato
表的实际主 id 字段,而且您应该只在主 id 字段而不是其他外部 id 中使用
#[ORM\Id]
...这是取自 symfony 演示的示例应用程序:


...
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'IDENTITY')]
    #[ORM\Column(type: 'integer')]
    private $id;

    #[ORM\ManyToOne(targetEntity: User::class)]
    #[ORM\JoinColumn(nullable: false)]
    private ?User $author = null;
...
© www.soinside.com 2019 - 2024. All rights reserved.