Doctrine Schema Validation Problems, and how to fix them

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

followed by:

php app/console doctrine:schema:validate

And the entities were magically happy again.

This fix works well for many doctrine issues I find.

Be Sociable, Share!

Leave a Reply

Your email address will not be published. Required fields are marked *

This blog is kept spam free by WP-SpamFree.