Symfony cmd 错误"目标实体"。找不到.."



我从Symfony Framework开始,我正在尝试建立ManyToMany关系。 但是当我尝试这个命令行时

php bin/console doctrine:schema:update

我收到此错误:

The target-entity C:xampphtdocssymfony-tpsrcEntityCompetetence cannot be found in 'AppEntityStagiaire#competencies'.

斯塔吉艾尔.php

<?php
namespace AppEntity;
use DoctrineORMMapping as ORM;
/**
* @ORMEntity(repositoryClass="AppRepositoryStagiaireRepository")
*/
class Stagiaire
{
/**
* @ORMManyToMany(targetEntity="C:xampphtdocssymfony-tpsrcEntityCompetetence",cascade={"persist"})
*/
private $competencies;
/**
* @ORMId()
* @ORMGeneratedValue()
* @ORMColumn(type="integer")
*/
private $id;
/**
* @ORMColumn(type="datetime")
*/
private $createdAt;
/**
* @ORMColumn(type="string", length=50)
*/
private $name;
/**
* @ORMColumn(type="integer")
*/
private $phone;
/**
* @ORMColumn(type="datetime")
*/
private $birthday;
/**
* @var Datetime
*/
private $date;
public function __construct()
{
$this->date = new Datetime();
$this->competencies = new ArrayCollection();
}
public function addCompetence(Competence $competence)
{
$this->$competence[] = $competence;
return $this;
}
public function removeCompetence(Competence $competence)
{
$this->competencies->removeElement($competence);
}
public function getCompetencies()
{
return $this->competencies;
}
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 getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getPhone(): ?int
{
return $this->phone;
}
public function setPhone(int $phone): self
{
$this->phone = $phone;
return $this;
}
public function getBirthday(): ?DateTimeInterface
{
return $this->birthday;
}
public function setBirthday(DateTimeInterface $birthday): self
{
$this->birthday = $birthday;
return $this;
}
}

能力.php

<?php
namespace AppEntity;
use DoctrineORMMapping as ORM;
use DoctrineCommonCollectionsArrayCollection;
/**
* @ORMEntity(repositoryClass="AppRepositoryCompetenceRepository")
*/
class Competence
{
/**
* @ORMId()
* @ORMGeneratedValue()
* @ORMColumn(type="integer")
*/
private $id;
/**
* @ORMColumn(type="string", length=50)
*/
private $name;
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
}

感谢您的帮助!

Stagiaire::$competencies注释中,您需要提供Competence的完全限定类名而不是计算机上的文件路径,这将AppEntityCompetence

所以这个:

/**
* @ORMManyToMany(targetEntity="C:xampphtdocssymfony-tpsrcEntityCompetetence",cascade={"persist"})
*/
private $competencies;

成为:

/**
* @ORMManyToMany(targetEntity="AppEntityCompetence",cascade={"persist"})
*/
private $competencies;

最新更新