From: Moritz Bunkus Date: Tue, 15 Jan 2013 13:46:30 +0000 (+0100) Subject: Vor Fremdschlüsselzuweisung trans_id verwaiste Einträge in orderitems löschen X-Git-Tag: release-3.1.0beta1~693 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=6f266e929ff3eaefc84c34b46fa452c50eecbcf4;p=kivitendo-erp.git Vor Fremdschlüsselzuweisung trans_id verwaiste Einträge in orderitems löschen --- diff --git a/sql/Pg-upgrade2/orderitems_delivery_order_items_invoice_foreign_keys.sql b/sql/Pg-upgrade2/orderitems_delivery_order_items_invoice_foreign_keys.sql index 0de00c5d3..ed1b01795 100644 --- a/sql/Pg-upgrade2/orderitems_delivery_order_items_invoice_foreign_keys.sql +++ b/sql/Pg-upgrade2/orderitems_delivery_order_items_invoice_foreign_keys.sql @@ -10,6 +10,8 @@ UPDATE orderitems SET project_id = NULL WHERE project_id NOT IN (SELEC UPDATE delivery_order_items SET project_id = NULL WHERE project_id NOT IN (SELECT id FROM project); UPDATE invoice SET project_id = NULL WHERE project_id NOT IN (SELECT id FROM project); +DELETE FROM orderitems WHERE trans_id NOT IN (SELECT id FROM oe); + ALTER TABLE orderitems ADD FOREIGN KEY (trans_id) REFERENCES oe (id); ALTER TABLE orderitems ADD FOREIGN KEY (project_id) REFERENCES project (id); ALTER TABLE orderitems ADD FOREIGN KEY (pricegroup_id) REFERENCES pricegroup (id);