Assistance: Could not delete due to association with another object: DataValue

Hi all,

I have deleted values from a data set through import, but when I try to delete data elements, I get this message: ’ Could not delete due to association with another object: DataValue’. Do the values still remain on the database? I cleared browser after deleting values.

[DHIS 2 version 2.34.4]


Hello @dmbantu

I think deleting values from dhis 2 web application will not delete them from the data values audit table (datavalueaudit). you have to delete them by using SQL in the database.

Hi @didate,

I am wondering if you could help me with the SQL script to delete values from the datavalueaudit table in the database


Hello @dmbantu ,

if you are not a database specialist please don’t do anything.

Ok first of all you have to backup your database.

Here is the datavalueaudit table structure

As you see this table use dataelementid as a foreign key, so you have to know the ID of your dataelement.

Here is the Query to get the ID of dataElement

select dataelementid from dataelement where uid='theUIDofyourdataElement';

Do you how to get UID of your dataElement ? You can get it in Maintenance → Data Element → Action Menu - > Details

Now you can delete values from datavalueaudit based on the dataelementid with the following query

delete from datavalueaudit where dataelementid='theIDofyourdataElement';

Hi @didate;

I am not a database specialist. I am very grateful for your didactic explanation.

I have also been looking for documentation or manual about how the DHIS 2 database is structured. Without your help, I wouldn’t have known that the dataelement table is related to datavalueaudit table. Is there any documentation or manual available about relationships between tables that make up the DB?

In your example above. it is pretty clear how the DE table and the datavalueaudit are related because of foreign keys.

Thanks again

Hello @dmbantu ,

I’m glad that my explanations helped you solve your problem.

I don’t think there is any documentation on the structure of the database .

But If you have any specific question do not hesitate.


1 Like

Hi @didate,

Tracker programs have also aroused interest. I have built some tracker programs but I do not how tracked entites, program stages, Program stages DEs, etc are related. I would like to have a clear image of how tables are related in tracker programs


1 Like

@dmbantu this has been discussed in this topic: Database Scheme of DHIS2 Tracker You might find it helpful! (:

1 Like

Thank you @Gassim for this wonderful resource.

1 Like

You’re welcome! And thank you for the great help. :pray: I didn’t do anything, it’s @jaime.bosque :grin:

1 Like