Cannot delete document due to reference error despite document not being used

18 replies
Last updated: Jan 28, 2026
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"
AI Update

I understand your frustration! This error occurs because Sanity uses strong references to maintain referential integrity - documents that are referenced by other documents cannot be deleted to prevent broken links.

The good news is that the error message actually tells you which document is referencing the one you're trying to delete: 2a3d6c4b-f2bf-47ab-bf9f-e90709b88b79. Here's how to resolve this:

Step 1: Find the referencing document

Open the referencing document in Sanity Studio by navigating to:

https://your-project.sanity.studio/desk/YOUR_DOCUMENT_TYPE;2a3d6c4b-f2bf-47ab-bf9f-e90709b88b79

Or use Vision (the GROQ query tool in your Studio) to find it:

*[_id == "2a3d6c4b-f2bf-47ab-bf9f-e90709b88b79"]

If you need to find all documents that reference your target document, use this GROQ query:

*[references("25e2930f-4a28-48c6-8e08-673d8ab9e0ad")]

The references() function in GROQ will find any document that has a reference field pointing to your document.

Step 2: Remove or update the reference

Once you've found the referencing document(s), you have a few options:

  1. Remove the reference field - Edit the referencing document and clear the reference field
  2. Point it to a different document - Update the reference to point to another valid document
  3. Delete the referencing document - If you don't need it either

You can also use the CLI to patch the document and remove the reference. For example, if the reference is in a field called myReference:

sanity documents patch 2a3d6c4b-f2bf-47ab-bf9f-e90709b88b79 --unset myReference

Step 3: Try deleting again

After removing all references, you should be able to delete your original document:

sanity documents delete 25e2930f-4a28-48c6-8e08-673d8ab9e0ad

Alternative: Use weak references in the future

If you need references that don't prevent deletion, you can configure your schema to use weak references by setting weak: true in your reference field definition. Weak references allow the referenced document to be deleted without blocking, though this means you could end up with broken references.

The error message will keep telling you which documents are blocking the deletion, so you may need to repeat this process if multiple documents reference the one you're trying to delete.

Show original thread
18 replies

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?