I am new to Symfony and trying to setup entities and relationships. Even though I seemed to have correctly annotated the primary keys.
When running
php bin/console doctrine:schema:validate
I got an error as follows:
The referenced column name 'brandId' has to be a primary key column on the target entity class 'AppBundle\Entity\Brands'.
The entities look like ( only relevant portions):
Thanks
Brands
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity
* @ORM\Table(name="brands")
*/
class Brands
{
/**
* @ORM\Id
* @ORM\Column(type="smallint",length=3,unique=true,options={"unsigned":true})
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $brandId;
/**
* one brands has many models
* @ORM\OneToMany(targetEntity="Models", mappedBy="brandId")
* @ORM\JoinColumn(name="brandId", referencedColumnName="brandId")
*/
private $models;
public function __construct()
{
$this->models = new ArrayCollection();
}
Models:
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="AppBundle\Repository\ModelsRepository")
* @ORM\Table(name="models")
*/
class Models
{
/**
* @ORM\Column(type="smallint",length=4,unique=true,options={"unsigned":true})
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $modelId;
/**
* @ORM\Column(type="string", length=25)
*/
private $model;
/**
* Many models for one brand
* @ORM\ManyToOne(targetEntity="Brands",inversedBy="models")
* @ORM\JoinColumn(name="brandId", referencedColumnName="brandId")
*/
private $brandId;