如何在 Doctrine 迁移中添加关系

发布于 2024-10-04 11:00:15 字数 286 浏览 0 评论 0原文

我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薄荷港 2024-10-11 11:00:15

我发现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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文