
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI understand your frustration - this is a common challenge when learning Sanity! The good news is that you can reorganize your schema structure without losing content, but it's important to understand what's actually happening under the hood.
The folder structure (schema/sections/abc/hero.js) is purely for your organization - Sanity doesn't care about it at all. What Sanity does care about is the _type field stored in each document. This is what identifies the schema type.
However, there's a critical constraint: the _type field is immutable. According to the official Sanity migration documentation, you cannot change _type, _id, _createdAt, _updatedAt, or _rev once they're set. These are immutable properties in the Content Lake.
Instead of trying to have multiple schemas with the same name in different folders, you should give each schema a unique name property that reflects its context:
schema/
documents/
objects/
sections/
abc/
abcHero.js // name: 'abcHero'
xyz/
xyzHero.js // name: 'xyzHero'In each schema file, make sure the name field is unique:
// schema/sections/abc/abcHero.js
export default {
name: 'abcHero', // This is what becomes _type
type: 'object',
title: 'ABC Hero Section',
fields: [
// your fields
]
}If you've already created content with conflicting schema names, you'll need to migrate the data. Since _type is immutable, you can't use the standard migration toolkit's at('_type', set(...)) approach. Instead, you need to:
sanity dataset export production --no-assetsThis creates a .tar.gz file containing an NDJSON file with all your documents.
tar -xzvf production.tar.gzOpen the .ndjson file and find/replace the _type values. For example, change documents from:
{"_id": "abc123", "_type": "hero", ...}to:
{"_id": "abc123", "_type": "abcHero", ...}Important: You'll also need to update any references to these documents throughout your dataset. If other documents reference these by type (in arrays with type filters, for example), those need updating too.
Before reimporting, update your schema files with the new unique names.
If you're keeping the same _id values but changing the _type, you'll need to delete the old documents first. Create a migration:
import {defineMigration, delete_} from 'sanity/migrate'
export default defineMigration({
title: 'Delete old hero documents',
documentTypes: ['hero'], // the old type name
migrate: {
document(doc) {
return delete_(doc._id)
}
}
})Run this with:
sanity migration run "Delete old hero documents" --dataset productionsanity dataset import production.ndjson production --replaceIf the above seems too risky, you could also:
abcHero, xyzHero)This is safer but more manual work.
To avoid this entirely, establish a naming convention from the start:
homeHero, productHero, aboutHeropageHero, postHerofullWidthHero, splitHero, etc.The folder structure is just for your convenience - the name field in the schema is what matters to Sanity.
npx sanity documents validate after migration to ensure everything is correctThe key takeaway: organize your files however you want, but make sure every schema has a unique name property. That's what Sanity uses to identify content types, not the file structure. The migration cheat sheet has more examples of common migration patterns, though changing _type specifically requires the export/modify/reimport approach.
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