Search code examples
entity-frameworksymfonysymfony3

Symfony - The mappings are inconsistent with each other - The association refers to the inverse side field which does not exist


Hello I try to make a OntToMany ond ManyToOne connexions but I have this following errors:

The mappings MySqlBundle\Entity\GENERAL\Categorie#SOCIETES and MySqlBundle\Entity\GENERAL\Societe#CATEGORIE are inconsistent with each other.

The association MySqlBundle\Entity\GENERAL\Societe#CATEGORIE refers to the inverse side field MySqlBundle\Entity\GENERAL\Categorie#Societe which does not exist.

My Categorie entity:

/**
 * @ORM\Table(name="Categorie")
 * @ORM\Entity(repositoryClass="MySqlBundle\Repository\GENERAL\Categories_Repository")
 */
class Categorie
{
    public function __construct() {
        $this->SOCIETES = new ArrayCollection();
    }

   /**
     * @var integer
     *
     * @ORM\Column(name="ID", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
   public $Id;

   /**
     * @var text
     *
     * @ORM\Column(name="DESCRIPTION", type="text", nullable=true)
     */
   public $DESCRIPTION;

   /**
     * @var integer
     *
     * @ORM\Column(name="ORDRE", type="integer", nullable=false)
     */
   public $ORDRE;   

   /**
     * @ORM\OneToMany(targetEntity="Societe", mappedBy="CATEGORIE")
     */
    private $SOCIETES;

My societe entity :

/**
 * @ORM\Table(name="Societe")
 * @ORM\Entity(repositoryClass="MySqlBundle\Repository\GENERAL\Societe_Repository")
 */
class Societe
{
   /**
     * @var integer
     *
     * @ORM\Column(name="ID", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
   public $Id;

   /**
     * @var string
     *
     * @ORM\Column(name="NOM", type="string", length=255)
     */
   public $NOM;

    /**
     * @var string
     *
     * @ORM\Column(name="INFO", type="string", length=255, nullable=true)
     */
   public $INFO;

   /**
     * @var string
     *
     * @ORM\Column(name="HOST", type="string", length=255, nullable=true)
     */
   public $HOST;

   /**
     * @var string
     *
     * @ORM\Column(name="NOM_USER", type="string", length=255, nullable=true)
     */
   public $NOM_USER;

   /**
     * @var string
     *
     * @ORM\Column(name="MDP", type="string", length=255, nullable=true)
     */
   public $MDP;

   /**
     * @ORM\ManyToOne(targetEntity="Categorie", inversedBy="Societe")
     * @ORM\JoinColumn(name="ID_CATEGORIE", referencedColumnName="ID")
     */
    private $CATEGORIE;

If you have an idea, I've checked the spelling (by copied and pasted), and even when reading the errors again I can't correct them.

I didn't put the getters and setters, but if you want them, no problem.


Solution

  • You have to match the names. In this case you want to capitalize "SOCIETES" like this:

     /**
     * @ORM\ManyToOne(targetEntity="Categorie", inversedBy="SOCIETES")
     * @ORM\JoinColumn(name="ID_CATEGORIE", referencedColumnName="ID")
     */
    private $CATEGORIE;