X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/b9043da3207903443bc94320b5f5f981f20c3698..af131a46:/sql/Pg-upgrade2/customer_add_constraints.sql?ds=sidebyside

diff --git a/sql/Pg-upgrade2/customer_add_constraints.sql b/sql/Pg-upgrade2/customer_add_constraints.sql
index 6505efdb1..60f73bbb7 100644
--- a/sql/Pg-upgrade2/customer_add_constraints.sql
+++ b/sql/Pg-upgrade2/customer_add_constraints.sql
@@ -1,9 +1,13 @@
 -- @tag: customer_add_constraints
 -- @description: ZusÃ¤tzliche FremdschlÃ¼ssel fÃ¼r Sprache, Kundentyp und Zahlungskonditionen
 -- @depends: release_2_6_3
--- @charset: utf-8
 -- @ignore: 0
 
+-- verwaiste EintrÃ¤ge vorher entfernen
+UPDATE customer SET payment_id  = NULL WHERE payment_id  NOT IN (SELECT id FROM payment_terms);
+UPDATE customer SET language_id = NULL WHERE language_id NOT IN (SELECT id FROM language);
+UPDATE customer SET business_id = NULL WHERE business_id NOT IN (SELECT id FROM business);
+
 ALTER TABLE customer ADD FOREIGN KEY (payment_id) REFERENCES payment_terms (id);
 ALTER TABLE customer ADD FOREIGN KEY (language_id) REFERENCES language (id);
 ALTER TABLE customer ADD FOREIGN KEY (business_id) REFERENCES business (id);
