Sanity Pioneers: Get early access to betas, extra AI credits, and a direct line to the engineering team. Apply now

How to unset/clear a nonexistent reference field in Sanity CMS

23 repliesLast updated: Nov 29, 2025

I have a product in my Sanity CMS with a field that shows
<nonexistent reference>
how do I unset this reference, there isn’t an earlier version to restore to
AI Update

I understand the frustration! When you see <nonexistent reference> in Sanity Studio, it means the document that was referenced has been deleted, but the reference field still points to it. Here's how to clear it:

Using Vision Tool (Quick GUI Method)

The easiest way is to use the Vision tool built into Sanity Studio to run a patch mutation:

{
  "mutations": [
    {
      "patch": {
        "id": "YOUR_DOCUMENT_ID",
        "unset": ["yourFieldName"]
      }
    }
  ]
}

The unset operation removes the field entirely from your document, clearing the broken reference.

Using the Sanity CLI

You can also run this from your terminal using the Sanity CLI:

sanity documents query '*[_id == "YOUR_DOCUMENT_ID"][0]' | \
sanity documents patch --unset yourFieldName

Or create a migration script:

import {getCliClient} from 'sanity/cli'

const client = getCliClient()

client
  .patch('YOUR_DOCUMENT_ID')
  .unset(['yourFieldName'])
  .commit()
  .then(() => console.log('Reference cleared!'))
  .catch(err => console.error(err))

For Nested Fields

If the reference is nested in an object or array, adjust the path accordingly. For example, if it's inside an object:

.unset(['parentObject.yourFieldName'])

Or if it's in a specific array item (using the item's _key):

.unset(['arrayField[_key=="abc123"].referenceField'])

After running the patch, refresh Studio and the <nonexistent reference> should be gone. You can then set a new valid reference if needed, or leave the field empty.

Show original thread
23 replies

Was this answer helpful?

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.

Related contributions