Home > Blockchain >  Create migration from entity file
Create migration from entity file

Time:04-29

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.

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

CodePudding user response:

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.

  • Related