Postgresql 不使用 DELETE CASCADE 进行删除
我有一些行要从表中删除:
DELETE FROM my_table WHERE id=1
但是 id=1 的行在 another_table
中作为外键引用。
在理想的情况下,它会级联并删除 another_table
中的相关条目。但是,外键不是作为级联删除引用的,并且 null=False。因此,使用上面的查询无法删除 my_table 中 id=1 的元素,因为这会导致 another_table
中出现完整性错误。
是否有类似的内容:
DELETE CASCADE FROM my_table WHERE id=1
哪个删除相关的外键?
或者还有另一种方法可以做到这一点吗?
谢谢。
I have some rows to delete from a table:
DELETE FROM my_table WHERE id=1
However the row with id=1 is referenced in another_table
as a foreign key.
In an ideal world, it would cascade and also delete the related entry in another_table
. However the foreign key wasn't references as cascade delete and has null=False. So deleting the element with id=1 in my_table cannot be achieved with the query from above because it would cause an integrity error in another_table
.
Is there something like:
DELETE CASCADE FROM my_table WHERE id=1
Which deletes related foreign keys?
Alternatively is there another way to do this?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论