Need guidance on removing a field from the schema in an app using Sanity.io
Good question! When you remove a field from your Sanity schema, the existing data in documents that have that field will not be automatically deleted. This is actually a feature designed to prevent unintended data loss.
What happens to the existing data?
The data remains in your documents in the Content Lake. Sanity treats schema changes as non-destructive by default - changing your schema doesn't cascade changes to existing content. This helps prevent breakage for applications that might still rely on that data.
What you should consider doing:
Mark the field as deprecated first (optional but recommended for production projects)
You can use the
deprecatedproperty in your schema to mark fields that shouldn't be used anymore:defineField({ name: 'oldFieldName', type: 'string', deprecated: { reason: 'This field is no longer used' }, readOnly: true // prevents further edits })Decide if you need to clean up the data
You have a few options:
- Leave the data as-is (it won't hurt anything)
- Use a content migration to remove the field data from existing documents
- Use the
sanity documents validateCLI command to check which documents still have that field
Run a migration to remove the data (if needed)
If you want to actually remove the field data from existing documents, you can create a migration script using
sanity migration createand use theunset()helper function.
Where to find more information:
The main documentation page you want is: Migrating your schema and content
Also helpful:
- Content migration cheat sheet - copy-paste examples for common migration tasks
- Schema migration principles - best practices for handling schema changes
The short version: you're safe to remove the field from your schema without worrying about data loss. The old data will just sit there harmlessly unless you explicitly remove it with a migration.
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.