I’m having issue with OptionSet after doing dhis2 migration to version 2.40. I had a successful database restore but I get popup message Can not add a Model without id to a ModelCollection Ok whenever I click on any OptionSet.
What I have tried.
I have manually updated the sortOrder for options under each optionSet id. However when importing the metadata, the process fails with:
TypeError: Cannot read properties of undefined (reading ‘imported’)
TypeError: Cannot read properties of undefined (reading ‘imported’)
What could be the issue? Do I have to upgrade one version at a time?
Thanks @Gassim,
I just exported the entire metadata for my instance through import/export app. I used the default selections without unselecting anything.
I found an interesting solution shared by @stratosilva in this post
So, the solution is to edit optionvalue table to re-order sortOrder properly before exporting metadata from the source instance. You may also have to run the same query on the destination database too.
Here is the query:
postgres~# \c dhis_db
dhis_db=># UPDATE optionvalue SET sort_order = temp.orderIndex FROM ( SELECT optionvalueid, optionsetid, row_number() OVER ( PARTITION BY optionsetid ORDER BY sort_order ) AS orderIndex FROM optionvalue ) temp WHERE temp.optionvalueid = optionvalue.optionvalueid AND temp.optionsetid = optionvalue.optionsetid AND ( optionvalue.sort_order <> temp.orderIndex OR optionvalue.sort_order IS NULL );