title: Column name referenced for relation not exist - ManyToMany relationship Symfony Doctrine
body: <p>I have a little problem with Doctrine and Symfony 5.4. I've searched on StackOverflow and on the doc, but every solution seems that is not correctly for me.</p>
  <p>I have 3 class: Lang, State, OrderState. Last one is join with Lang and State through id_state and id_lang with a ManyToMany association relation ship.</p>
  <p>When i execute the schema validate, i get the classic error. Honestly i don't understand why.</p>
  <pre><code>    Mapping
  -------
  
   [FAIL] The entity-class App\Entity\OrderState mapping is invalid:
   * The referenced column name 'id_state' has to be a primary key column on the target entity class 'App\Entity\OrderState'.
   * The referenced column name 'id' has to be a primary key column on the target entity class 'App\Entity\Lang'.
  
  
  Database
  --------
  
  
  In MissingColumnException.php line 15:
                                                                                     
    Column name &quot;id_state&quot; referenced for relation from App\Entity\OrderState towa   
    rds App\Entity\State does not exist.    
  </code></pre>
  <p>State.php</p>
  <pre><code>&lt;?php
  
  namespace App\Entity;
  
  use App\Repository\StateRepository;
  use Doctrine\Common\Collections\ArrayCollection;
  use Doctrine\Common\Collections\Collection;
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * @ORM\Entity(repositoryClass=StateRepository::class)
   */
  class State
  {
      /**
       * @ORM\Id
       * @ORM\GeneratedValue(strategy=&quot;AUTO&quot;)
       * @ORM\Column(type=&quot;integer&quot;)
       */
      private $id_state;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255)
       */
      private $label;
  
  
      public function getIdState(): ?int
      {
          return $this-&gt;id_state;
      }
  
      public function getLabel(): ?string
      {
          return $this-&gt;label;
      }
  
      public function setLabel(string $label): self
      {
          $this-&gt;label = $label;
  
          return $this;
      }
  
     
  }
  </code></pre>
  <p>Lang.php</p>
  <pre><code>    &lt;?php
  
  namespace App\Entity;
  
  use App\Repository\LangRepository;
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * @ORM\Entity(repositoryClass=LangRepository::class)
   */
  class Lang
  {
      /**
       * @ORM\Id
       * @ORM\GeneratedValue(strategy=&quot;AUTO&quot;)
       * @ORM\Column(type=&quot;integer&quot;)
       */
      private $id_lang;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255)
       */
      private $lang;
  
      public function getIdLang(): ?int
      {
          return $this-&gt;id_lang;
      }
  
      public function setIdLang(int $id_lang): self
      {
          $this-&gt;id_lang = $id_lang;
  
          return $this;
      }
  
      public function getLang(): ?string
      {
          return $this-&gt;lang;
      }
  
      public function setLang(string $lang): self
      {
          $this-&gt;lang = $lang;
  
          return $this;
      }
  }
  </code></pre>
  <p>and OrderState.php</p>
  <pre><code>&lt;?php
  
  namespace App\Entity;
  
  use App\Repository\OrderStateRepository;
  use Doctrine\Common\Collections\ArrayCollection;
  use Doctrine\Common\Collections\Collection;
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * @ORM\Entity(repositoryClass=OrderStateRepository::class)
   */
  class OrderState
  {
      /**
       * @ORM\Id
       * @ORM\GeneratedValue
       * @ORM\Column(type=&quot;integer&quot;)
       */
      private $id;
  
      /**
       * @ORM\ManyToMany(targetEntity=State::class)
       * @ORM\JoinColumn(name=&quot;id_state&quot;, referencedColumnName=&quot;id_state&quot;)
       */
      private $id_state;
  
      /**
       * @ORM\ManyToMany(targetEntity=Lang::class)
       * @ORM\JoinColumn(name=&quot;id_lang&quot;, referencedColumnName=&quot;id_lang&quot;)
       */
      private $id_lang;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255, nullable=true)
       */
      private $state;
  
      public function __construct()
      {
          $this-&gt;id_state = new ArrayCollection();
          $this-&gt;id_lang = new ArrayCollection();
      }
  
      public function getId(): ?int
      {
          return $this-&gt;id;
      }
  
      /**
       * @return Collection&lt;int, State&gt;
       */
      public function getIdState(): Collection
      {
          return $this-&gt;id_state;
      }
  
      public function addIdState(State $idState): self
      {
          if (!$this-&gt;id_state-&gt;contains($idState)) {
              $this-&gt;id_state[] = $idState;
          }
  
          return $this;
      }
  
      public function removeIdState(State $idState): self
      {
          $this-&gt;id_state-&gt;removeElement($idState);
  
          return $this;
      }
  
      /**
       * @return Collection&lt;int, Lang&gt;
       */
      public function getIdLang(): Collection
      {
          return $this-&gt;id_lang;
      }
  
      public function addIdLang(Lang $idLang): self
      {
          if (!$this-&gt;id_lang-&gt;contains($idLang)) {
              $this-&gt;id_lang[] = $idLang;
          }
  
          return $this;
      }
  
      public function removeIdLang(Lang $idLang): self
      {
          $this-&gt;id_lang-&gt;removeElement($idLang);
  
          return $this;
      }
  
      public function getState(): ?string
      {
          return $this-&gt;state;
      }
  
      public function setState(?string $state): self
      {
          $this-&gt;state = $state;
  
          return $this;
      }
  }
  </code></pre>