Doctrine has a habit of throwing strange errors my way – usually when things look like they should just work.
As I encounter more of them, I will add them below.
The referenced column name ‘your_field_name’ has to be a primary key column on the target entity class ‘My\FriendlyBundle\Entity\EntityName’
You may be thinking – well, just add the primary key, as it’s suggesting. But no, that would have been silly.
Instead, as is usually the case, I deleted the problem fields on both ends, and recreated them using my MySQL tool of choice, SQLyog.
After that, the foreign key relationship was recreated. Then I ran:
php app/console doctrine:mapping:import CoreDatabaseBundle annotation
php app/console doctrine:schema:validate
And the entities were magically happy again.
This fix works well for many doctrine issues I find.