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

23 replies
Last updated: Jan 28, 2026
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:

  1. Open Vision from your Studio toolbar
  2. Switch from the "Query" tab to the "Params" section
  3. Paste this mutation (replace YOUR_DOCUMENT_ID and yourFieldName with your actual values):
{
  "mutations": [
    {
      "patch": {
        "id": "YOUR_DOCUMENT_ID",
        "unset": ["yourFieldName"]
      }
    }
  ]
}
  1. Click "Execute" to run the mutation

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

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?