简体   繁体   English

从实体文件创建迁移

[英]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.在 SQL 中,字段只有对另一个表的引用。

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.现在,我想创建一个迁移文件,并运行bin/console doctrine:migrations:diff ,但它没有为此添加约束修改。

Is it possible to generate a migration file only for this entity?是否可以仅为该实体生成迁移文件?

Cascade persist will not be handled by your database, because it's related to how doctrine handle entities with the UnitOfWork. Cascade persist 不会由您的数据库处理,因为它与 doctrine 如何使用 UnitOfWork 处理实体有关。

Cascade delete can be managed by doctrine or your database.级联删除可以通过 doctrine 或您的数据库进行管理。

Using cascade={"remove"} does not affect your database schema, as opposed to using onDelete .与使用onDelete相反,使用cascade={"remove"}不会影响您的数据库模式。

That's the reason you do not see any change because there is no SQL to be executed to update your entity schema.这就是您看不到任何更改的原因,因为没有要执行的 SQL 来更新您的实体模式。

Basically, cascade={"remove"} will only be used by doctrine and its UnitOfWork when an $entityManager is used to remove an entity.基本上,当$entityManager用于remove实体时, cascade={"remove"}将仅由 doctrine 及其 UnitOfWork 使用。

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.这就是为什么如果您在 SQL 中执行删除其中一个条目的原始查询,级联选项将不会执行任何操作,如果您使用原始 sql 而不是 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.因此,如果您不在代码中使用任何会删除条目的原始 sql,那么什么都不做也没关系。

Otherwise, you can use onDelete which will modify your database structure.否则,您可以使用 onDelete 来修改您的数据库结构。

You only need to do it for remove like this:你只需要像这样remove

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

Be sure to check the documentation if you use it to understand more about it.如果您使用它来了解更多信息,请务必查看文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM