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

**URL:** <https://community.dhis2.org/t/object-could-not-be-deleted-because-it-is-associated-with-another-object-trackedentityinstance/56122>\
**Category:** Support - Assistance technique\
**Tags:** tracker, events, maintence-app\
**Created:** [6 December 2023 09:57 UTC](https://community.dhis2.org/t/object-could-not-be-deleted-because-it-is-associated-with-another-object-trackedentityinstance/56122 "2023-12-06T09:57:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AllanLusui](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/allanlusui/32/48813_2.png) [@AllanLusui](https://community.dhis2.org/u/AllanLusui)\
**Post date:** [6 December 2023 09:57 UTC](https://community.dhis2.org/t/object-could-not-be-deleted-because-it-is-associated-with-another-object-trackedentityinstance/56122/1 "2023-12-06T09:57:59Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Gassim](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/gassim/32/35347_2.png) [@Gassim](https://community.dhis2.org/u/Gassim)\
**Post date:** [6 December 2023 16:58 UTC](https://community.dhis2.org/t/object-could-not-be-deleted-because-it-is-associated-with-another-object-trackedentityinstance/56122/2 "2023-12-06T16:58:36Z")

</div>

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=\*](https://play.dhis2.org/40.2.0/api/trackedEntityInstances/XnFPsDOVJND?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?

Thanks!

---

<div class="post-metadata">

**Author:** ![AllanLusui](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/allanlusui/32/48813_2.png) [@AllanLusui](https://community.dhis2.org/u/AllanLusui)\
**Post date:** [7 December 2023 06:39 UTC](https://community.dhis2.org/t/object-could-not-be-deleted-because-it-is-associated-with-another-object-trackedentityinstance/56122/3 "2023-12-07T06:39:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Gassim](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/gassim/32/35347_2.png) [@Gassim](https://community.dhis2.org/u/Gassim)\
**Post date:** [7 December 2023 19:58 UTC](https://community.dhis2.org/t/object-could-not-be-deleted-because-it-is-associated-with-another-object-trackedentityinstance/56122/4 "2023-12-07T19:58:07Z")

</div>

Hi @AllanLusui

Thanks for the clarification..

> [@AllanLusui](#):
>
> I also tracked the API yesterday and it shows `<deleted>false</deleted>`.

This means that the TEI is not being properly deleted.

---

<div class="post-metadata">

**Author:** ![AllanLusui](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/allanlusui/32/48813_2.png) [@AllanLusui](https://community.dhis2.org/u/AllanLusui)\
**Post date:** [11 December 2023 04:59 UTC](https://community.dhis2.org/t/object-could-not-be-deleted-because-it-is-associated-with-another-object-trackedentityinstance/56122/5 "2023-12-11T04:59:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Gassim](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/gassim/32/35347_2.png) [@Gassim](https://community.dhis2.org/u/Gassim)\
**Post date:** [11 December 2023 17:24 UTC](https://community.dhis2.org/t/object-could-not-be-deleted-because-it-is-associated-with-another-object-trackedentityinstance/56122/6 "2023-12-11T17:24:46Z")

</div>

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

Thanks!
