Error when deploying dhis2 version 2.39 to 2.40


Greetings, I am upgrading a backup of approximately 5GB in version 2.39.1.2 to the latest version of 2.40. The goal is to reach version 2.41, but I am encountering this bug.

I am open to solutions for resolving the bug.

Thanks

Hi @NelioChume ! There seems to be some lingering/obsolete database table with foreign constraints on the table that the migration file is trying to touch.

The table programtrackedentityattributegrouptranslations could be truncated. Could you try that?

TRUNCATE TABLE programtrackedentityattributegrouptranslations;

Please truncate first by running this in your db, and attempt to migrate again.

Please let us know how it goes.

regards

Ameen

Hi @Ameen! I ran the command you recommended, but it didn’t work completely.
However, it was very helpful because it gave me an idea of how to finish it and make it work properly.

These are the commands I executed:

  1. Confirm problematic constraint:
SELECT conname, conrelid::regclass
FROM pg_constraint
WHERE conname ILIKE '%programtrackedentityattributegroup%';

And I got the following result:

Constraint (conname) Tabela (conrelid)
fk_programtrackedentityattributegroupmembers_attributeid programtrackedentityattributegroupmembers
fk_programtrackedentityattributegroupmembers_groupid programtrackedentityattributegroupmembers
programtrackedentityattributegroupmembers_pkey programtrackedentityattributegroupmembers
fk_objecttranslation_programtrackedentityattributegroupid programtrackedentityattributegrouptranslations
programtrackedentityattributegrouptranslations_pkey programtrackedentityattributegrouptranslations

2. The second step was to remove ONLY the blocking constraints.

ALTER TABLE programtrackedentityattributegrouptranslations
DROP CONSTRAINT fk_objecttranslation_programtrackedentityattributegroupid;

ALTER TABLE programtrackedentityattributegroupmembers
DROP CONSTRAINT fk_programtrackedentityattributegroupmembers_groupid;

ALTER TABLE programtrackedentityattributegroupmembers
DROP CONSTRAINT fk_programtrackedentityattributegroupmembers_attributeid;

  1. Drop dependent tables
    DROP TABLE IF EXISTS programtrackedentityattributegrouptranslations;
    DROP TABLE IF EXISTS programtrackedentityattributegroupmembers;

Then restart the dhis2 instance and postgres.

Thanks for the update @NelioChume

Glad that the issue is resolved.

However, I’d like to point out that, the problematic (or obsolete) table was programtrackedentityattributegrouptranslations. Not the other table. You only had to drop that to make the upgrade work.

As part of v40 upgrade, we are removing programtrackedentityattributegroupmembers table as well, so I don’t see any further concerns since you have already upgraded.

But if you have not yet done this in a production instance and are planning to do it, please only perform the operations on programtrackedentityattributegrouptranslations table.

Thanks and regards
Ameen