Object could not be deleted because it is associated with another object: TrackedEntityInstance

I was trying to delete an org unit that had wrongly assigned TEIs.
I first deleted the TEIs
Then disassociated the programs from the org unit
Accessed maintenance to try and delete the org unit and I get the error (Object could not be deleted because it is associated with another object: TrackedEntityInstance)
Tried permanently deleting soft deleted TEIs, enrollments, events and even data values and still no solution
Kindly help!

Hi @AllanLusui

When you ran maintenance in the Data Administration app, did you run the Clear Application cache and reload apps options? Additionally, did you try to restart the server? Additionally, please make sure the OU is no longer assigned to any program or program stage. Finally, after all the above steps, could you use Guest mode in your browser to delete the OU?

If it’s not working still, before you see the error, could you open the Network tab (Devtools/F12) in your browser and check the error request, what is the id of the TEI?

If you find the id of the TEI, please check instanceURL/api/trackedEntityInstances/[replace here with TEI UID]?fields=*

After that, does it say <deleted>false</deleted> or <deleted>true</deleted>? Can you find it’s enrollment and go to it to make sure it’s deleted?


Hi Gassim!
I ran everything as explained in the first paragraph but still same error. I was testing all this in our nightly server which is set to clone our prod server every morning therefore this covers the restart part.

I also tracked the API yesterday and it shows <deleted>false</deleted>.
When I try to find it in the OU under the tracker capture I can’t see it, but when searching for it I can find it and it says it’s owned by the same OU. Also on searching it, there are no active enrollments/events.

Very weird i know but this is where I got stuck

Hi @AllanLusui

Thanks for the clarification…

This means that the TEI is not being properly deleted.

Thank you Gassim!
I was able to figure it out!

1 Like

@AllanLusui you’re welcome, so would you share what was the issue/solution? We’ll mark the post as solution as well.