Deleting a schema in Sanity does not delete related documents, but they can be deleted in batch using the CLI. The discussion also provides an explanation of how Sanity's...

9 replies
Last updated: Jul 10, 2023
Hello. Sanity internal working question.
Does removing schema delete related documents?
AI Update

No, removing a schema in Sanity does not automatically delete related documents.

This is actually a deliberate design choice that Sanity considers a feature. When you remove or change a schema type in your Sanity Studio configuration, the existing documents in your Content Lake remain untouched. This helps prevent unintended data loss and gives you full control over how to handle existing content.

Why this matters

Sanity treats schema changes similar to how databases handle data model changes - they should be intentional, reproducible, and part of your development workflow. Your content model and your actual data are kept separate, so removing a document type from your schema won't cascade into deleting the actual documents.

What happens to "orphaned" documents

When you remove a schema type:

  • Documents with that _type still exist in your dataset
  • They just won't be accessible through Studio anymore (since there's no schema to render them)
  • They'll still show up in API queries
  • The sanity documents validate CLI command will report them as documents with a _type not covered in your schema configuration

How to handle documents after removing a schema

You have several options:

  1. Keep them - If you might need the data later, just leave them. They don't hurt anything.

  2. Delete them manually - Use the HTTP API or write a script to delete documents of that type.

  3. Migrate them - Use content migrations to transform them into a different document type or structure.

  4. Mark as deprecated - Before removing a schema, you can mark it as deprecated with a reason, which will show warnings in Studio but keep everything accessible.

This separation between schema and data gives you flexibility to evolve your content model without risking accidental data loss.

Hi! No, deleting a schema does not impact your documents. If you have 30
post
documents and delete the
post
schema, those 30 documents will remain.
Thank you, (Removed Name). Can I delete them in batch then? Rather than individually. (from Studio, for e.g)
Just cripted the deletion of the latest document I removed
Two questions now:
• Can list existing documents?
• Does deleting all documents of a schema enough to delete get rid of that schema?
allo?
ping
Hi (Removed Name),
• You can list all of your existing documents using the
Vision plugin• You can
bulk delete documents with the cli, but that will not remove the schema
user T
, you have good answers from Sanity persons, but it's probably helpful to gain understanding of the system involved.
Sanity's Data Lake, where your data is stored, is a database -- built on the very capable globally high speed Google Cloud and BigQuery. This is not a SQL database, and is automatic as far as keeping track of its internal data schemas.

When you delete a schema original definition in your Studio source, the data and internal picture remain in the Data Lake -- you might still want to query it, so this is safe.

If you later write another version of that local Studio schema definition, then use it to enter data from the Studio, your fresh schema will be taken as the shape for the fresh data -- I am pretty confident without any need for extra actions by yourself.

This is provided you did your full delete of all prior data, as you have using sanity-cli (
sanity
calls from your terminal). If you forgot to do this, then you'd see alerts in the Studio pane where mismatched data would go, offering to delete that field entry, or if it can, to transform what doesn't fit.
At this point, you'd realize your mistake, stop the Studio, and do the full delete of that schema's documents, then return with your fresh schema. So you are safe to have things work according to your intentions.

The best way to be confident of understanding is to try your own experiments -- it's the kind of thing we do.

Add a test schema that you won't care about to your project. Put some simple data in it, a couple of records. Then modify the schema, and try entering data for this, so that you see the warnings come up for mismatches. Afterwards, use your
sanity
ccommand to delete the documents entirely. Now try entering from Studio again. Your new schema should be obeyed, and with no warnings. Now you are sure.
Good fortune,
(Removed Name)
This is an excellent explanation,
user Q
! Thank you!

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?