簡體   English   中英

在 postgres 的多個訂單表中,無法從表(訂單)中刪除其 id 列作為外鍵的記錄

[英]Not able to delete records from table(order) having its id column as foreign key in multiple order tables in postgres

我在下表dispatch_details order_histories sales_return_details Promotion_orders中有一個“ orders ”表,其 id 作為外鍵

在創建表時,我們沒有添加 ON DELETE CASCADE。 所以我從引用的表中刪除了所有必需的記錄,即dispatch_details、order_histories、sales_return_details 和promotion_orders。

即使我沒有收到任何錯誤,仍然無法從訂單中刪除記錄花費了太多時間。 它只是處理,但沒有完成。

我為所有引用的表進一步添加了索引。

create index idx_dispatch_details_order_id on dispatch_details(order_id);
create index idx_order_histories_order_id on order_histories(order_id);
create index idx_sales_return_details_order_id on sales_return_details(order_id);
create index idx_promotion_orders_order_id on promotion_orders(order_id);

不過,我無法刪除記錄。

有什么方法可以有效地從訂單中刪除記錄表? 目前,我什至無法從訂單中刪除單個記錄。

我進一步為所有表調用和daily_order_info 表添加了索引。 此外,orders 表具有對其自身的 parent_order_id FK 引用。 也為該列添加了索引。 基本上,對於所有引用的表:創建了一個索引並解決了我的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM