Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Create migration from entity file

I have some tables, which were modified. Added some annotation to some relation:

cascade={"persist", "remove"}

In the SQL, the fields have only a reference to another table.

Now, I want to create a migration file, and run bin/console doctrine:migrations:diff, but it does not add the constraint modification for this.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Is it possible to generate a migration file only for this entity?

>Solution :

Cascade persist will not be handled by your database, because it’s related to how doctrine handle entities with the UnitOfWork.

Cascade delete can be managed by doctrine or your database.

Using cascade={"remove"} does not affect your database schema, as opposed to using onDelete.

That’s the reason you do not see any change because there is no SQL to be executed to update your entity schema.

Basically, cascade={"remove"} will only be used by doctrine and its UnitOfWork when an $entityManager is used toremove an entity.

That’s why if you execute a raw query in SQL that remove one of your entry, the cascade option will not do anything which could indeed cause an error if you use raw sql instead of Doctrine DQL.

So if you don’t use any raw sql in your code that would remove an entry, it’s fine to not do anything.

Otherwise, you can use onDelete which will modify your database structure.

You only need to do it for remove like this:

cascade={"persist"}, onDelete="CASCADE"

Be sure to check the documentation if you use it to understand more about it.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading