diff --git a/html/admin/setup.php b/html/admin/setup.php
index f155f8d88..8631c55c7 100644
--- a/html/admin/setup.php
+++ b/html/admin/setup.php
@@ -277,7 +277,7 @@ for ($e=0;$e < $MaxDossier;$e++) {
$db_row=pg_fetch_array($Resdossier,$e);
echo "Patching ".$db_row['dos_name']."
";
$db=DbConnect($db_row['dos_id'],'dossier');
- if ( GetVersion($db) == 4 ) {
+ if ( GetVersion($db) == 3 ) {
ExecuteScript($db,'sql/patch/upgrade4.sql');
$sql="select jrn_def_id from jrn_def ";
diff --git a/html/admin/sql/account_repository/data.sql b/html/admin/sql/account_repository/data.sql
index f00181ada..2bc405264 100644
--- a/html/admin/sql/account_repository/data.sql
+++ b/html/admin/sql/account_repository/data.sql
@@ -49,7 +49,7 @@ INSERT INTO jnt_use_dos (jnt_id, use_id, dos_id) VALUES (23, 5, 1);
-- Name: version; Type: TABLE DATA; Schema: public; Owner: phpcompta
--
-INSERT INTO "version" (val) VALUES (4);
+INSERT INTO "version" (val) VALUES (3);
--
diff --git a/html/admin/sql/dossier1/data.sql b/html/admin/sql/dossier1/data.sql
index 4c16e68a8..14afa5f63 100644
--- a/html/admin/sql/dossier1/data.sql
+++ b/html/admin/sql/dossier1/data.sql
@@ -521,7 +521,7 @@ INSERT INTO tmp_pcmn (pcm_val, pcm_lib, pcm_val_parent, pcm_country) VALUES (604
-- Name: version; Type: TABLE DATA; Schema: public; Owner: phpcompta
--
-INSERT INTO "version" (val) VALUES (4);
+INSERT INTO "version" (val) VALUES (3);
--
diff --git a/html/admin/sql/mod1/data.sql b/html/admin/sql/mod1/data.sql
index f237a37c2..ec5004bbc 100644
--- a/html/admin/sql/mod1/data.sql
+++ b/html/admin/sql/mod1/data.sql
@@ -521,7 +521,7 @@ INSERT INTO tmp_pcmn (pcm_val, pcm_lib, pcm_val_parent, pcm_country) VALUES (101
-- Name: version; Type: TABLE DATA; Schema: public; Owner: phpcompta
--
-INSERT INTO "version" (val) VALUES (4);
+INSERT INTO "version" (val) VALUES (3);
--
diff --git a/html/admin/sql/patch/ac-upgrade4.sql b/html/admin/sql/patch/ac-upgrade4.sql
index deb335047..d613c5d8b 100644
--- a/html/admin/sql/patch/ac-upgrade4.sql
+++ b/html/admin/sql/patch/ac-upgrade4.sql
@@ -1,2 +1,4 @@
+delete from jnt_use_dos where dos_id not in (select dos_id from ac_dossier );
+
delete from jnt_use_dos where dos_id not in (select dos_id from ac_dossier);
-update version set val=4;
\ No newline at end of file
+update version set val=4;