如何在 Doctrine 迁移中添加关系
我有 3 个模型组成了多对多关系:Product、Color 和 ProductColor。一种产品可以有多种颜色。
经过一些开发后,我发现由于键约束,如果颜色出现在 ProductColor 表中,我无法删除它们。我尝试在 schema.yml 中添加从颜色到产品的关系,以便可以指定 onDelete 级联,但在运行“symfonydoctrine:generate-migrations-diff”时收到消息“无法从差异生成迁移类”。
我是否以错误的方式处理这个问题?如何使用迁移来更改与 onDelete 级联的关系?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现doctrine:generate-migrations-diff 非常不可靠。您可能必须使用doctrine:generate-migration 编写自己的迁移。您可能还应该检查冗余的 schema.yml 声明或其他生成不正确约束的问题。
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.