Struggling to delete a document in Sanity due to references, but issue was resolved.
18 replies
Last updated: Mar 7, 2022
D
Hello, I’m struggling to delete a document that I’m no longer using. However Sanity appears to believe it is still in use. I tried the CLI command to no avail (similar error)
sanity documents delete 25e2930f-4a28-48c6-8e08-673d8ab9e0ad
Error: Failed to delete document: the mutation(s) failed: Document "25e2930f-4a28-48c6-8e08-673d8ab9e0ad" cannot be deleted as there are references to it from "2a3d6c4b-f2bf-47ab-bf9f-e90709b88b79"
Mar 7, 2022, 7:15 PM
Hey Dani! You'd have to unset the reference to the document you want to delete in
2a3d6c4b-f2bf-47ab-bf9f-e90709b88b79. If I'm understanding correctly, are you saying that you believe you've already removed this reference in the Studio?
Mar 7, 2022, 7:19 PM
D
Hey Racheal, yes I’ve set it and unset it several times. I’ve also gone ahead and created a similar document and referred to that as a substitute then tried to delete the troublesome doc with no change in results
Mar 7, 2022, 7:22 PM
Hmm, if you query for the referring document (
2a3d6c4b-f2bf-47ab-bf9f-e90709b88b79) what does the data look like?
Mar 7, 2022, 7:24 PM
D
"result":[1 item 0:{8 items "_createdAt":"2022-01-20T15:28:26Z" "_id":"2a3d6c4b-f2bf-47ab-bf9f-e90709b88b79" "_rev":"r3bCIEX9U7jE5HgK6OeGj9" "_type":"settings" "_updatedAt":"2022-01-20T16:40:08Z" "footerNav":{1 item "footerNavSocial":{...}2 items } "name":"Footer Nav" "type":"footerNav" } ]
Mar 7, 2022, 7:24 PM
D
I can edit the data within that doc in the GUI
Mar 7, 2022, 7:24 PM
D
But I can’t seem to delete it
Mar 7, 2022, 7:24 PM
D
I can also create additional documents of that same type and point to them, but I still can’t delete it
Mar 7, 2022, 7:25 PM
D
I cleared the reference to it from the “footerNav” and then tried to unpublish and it gave me this error
the mutation(s) failed: Document "25e2930f-4a28-48c6-8e08-673d8ab9e0ad" cannot be deleted as there are references to it from "2a3d6c4b-f2bf-47ab-bf9f-e90709b88b79"
Mar 7, 2022, 7:26 PM
D
I cleared the reference to it from the “footerNav” and then tried to unpublish and it gave me this error
the mutation(s) failed: Document "25e2930f-4a28-48c6-8e08-673d8ab9e0ad" cannot be deleted as there are references to it from "2a3d6c4b-f2bf-47ab-bf9f-e90709b88b79"
Mar 7, 2022, 7:26 PM
D
oh shoot
Mar 7, 2022, 7:27 PM
D
i wonder if this referring doc is just a ghost doc that I stopped using
Mar 7, 2022, 7:27 PM
Or you can share the URL that Vision gives you when you run the query and I can poke around myself 🙂
Mar 7, 2022, 7:27 PM
D
wow I just figured it out
Mar 7, 2022, 7:28 PM
D
looks like that reference mentioned in my last code blog was for a “footerNav” that I had started and then changed the schema so it “disappeared” from the GUI but was still hanging around
Mar 7, 2022, 7:28 PM
D
i deleted that and then I could delete that first one which I thought was giving me all of my trouble
Mar 7, 2022, 7:29 PM
D
thanks for being my 🐥
Mar 7, 2022, 7:29 PM
Sanity– build remarkable experiences at scale
Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.