Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine 2 not creating foreign key

I have this piece of code inside an Entity:

/**
 * @ORM\ManyToOne(targetEntity="Centers")
 * @ORM\JoinColumn(name="center_id", referencedColumnName="id")
 * @ORM\Column(type="string", length=36, name="center_id")
 */
protected $centerId;

However, schema:update says that all is in sync. Even changing Centers to some other inexistent word, produces no error.

like image 228
JorgeeFG Avatar asked Jan 24 '26 22:01

JorgeeFG


1 Answers

Please delete the last line of annotation doctrine like this and change $centerId by $center (there is object an object) :

/**
 * @ORM\ManyToOne(targetEntity="Centers")
 * @ORM\JoinColumn(name="center_id", referencedColumnName="id")
 */
protected $center;

Clear cache and run your command.

Tell me if this solved your problem.

like image 57
Le Menach Florian Avatar answered Jan 27 '26 01:01

Le Menach Florian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!