
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI've seen this exact issue before! The error you're getting is because there's still a document somewhere in your Content Lake that references type B, even though it might not be visible in your Studio anymore.
When you removed type B from your schema, any documents that referenced it "disappeared" from the Studio GUI - but they're still in your dataset. These "ghost documents" can still hold references to other documents, which is why you're getting the error about references even after deleting the visible type A document.
This is actually documented in a resolved community case where someone had the exact same problem - they changed their schema and the referring document "disappeared" from the GUI but was still hanging around in the dataset.
Use Vision (or the CLI) to find and delete the hidden documents:
Open Vision in your Studio (the plugin that lets you run GROQ queries)
Query for all documents that reference type B:
*[references("YOUR_TYPE_B_DOCUMENT_ID")]Check the results - you'll likely find documents that aren't showing up in your Studio anymore because you removed their type from the schema
Delete these hidden documents using the CLI:
sanity documents delete DOCUMENT_IDOr if you see the document in Vision, note its _id and delete it
Alternative approach: If you know the type name that you removed from the schema, you can query for all documents of that type:
*[_type == "yourRemovedTypeName"]This will show you all the orphaned documents that are still hanging around after you removed the type from your schema.
When you change your schema and remove a document type, Sanity doesn't automatically delete the existing documents of that type from your dataset - it just makes them inaccessible through the Studio. This is actually a safety feature to prevent accidental data loss! But it does mean you need to manually clean up these documents before removing types that other documents reference.
Once you've deleted all the hidden documents that still reference type B (or that ARE type B), you should be able to remove type B from your schema without any errors.
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