Search code examples
symfony1doctrinedata-migration

How do I add a relation in a Doctrine Migration


I have 3 models that make up a many to many relation: Product, Color and ProductColor. A product can have many colors.

After doing some development I discovered that I couldn't delete colors if they appear in the ProductColor table because of a key constraint. I tried adding the relation from color to product in schema.yml so that I could specify onDelete cascade, but I get the message "Could not generate migration classes from difference" when running "symfony doctrine:generate-migrations-diff".

Am I going about this the wrong way? How can I use migrations to change the relation to onDelete cascade?


Solution

  • I find doctrine:generate-migrations-diff to be very unreliable. You may have to write your own migration using doctrine:generate-migration. You should probably also check for a redundant schema.yml declaration or other issue that is generating an incorrect constraint.