
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI 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:
The easiest way is to use the Vision tool built into Sanity Studio to run a patch mutation:
YOUR_DOCUMENT_ID and yourFieldName with your actual values):{
"mutations": [
{
"patch": {
"id": "YOUR_DOCUMENT_ID",
"unset": ["yourFieldName"]
}
}
]
}The unset operation removes the field entirely from your document, clearing the broken reference.
You can also run this from your terminal using the Sanity CLI:
sanity documents query '*[_id == "YOUR_DOCUMENT_ID"][0]' | \
sanity documents patch --unset yourFieldNameOr 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))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.
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store