Symfony cmd error "The target-entity..cannot be found in.."

I’m starting with Symfony Framework and I am trying to make ManyToMany relationship.
But when I try this commandline

php bin/console doctrine:schema:update

I am getting this error:

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

Stagiaire.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;
    }
}

Competence.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;
    }
}

Thanks for your help !

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *