
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeUnfortunately, you've discovered one of the fundamental constraints of Sanity's Content Lake: the _type attribute is immutable and cannot be changed after a document is created. This is by design to maintain data integrity and consistent relationships between documents and their schemas.
When you renamed the document type in your schema, it created a mismatch - the old documents still have the original _type value, but your schema no longer recognizes that type, which is why you can't access them in Studio.
Since you can't modify _type directly (even through export/import), you need to create entirely new documents with the new type. Here's how to approach this:
The Sanity CLI migration tool is built for exactly this scenario:
npx sanity@latest migration create changeDocumentTypeThen write a migration script that:
_type_type and copies all the contentimport {defineMigration, at, setIfMissing} from 'sanity/migrate'
export default defineMigration({
title: 'Change document type from oldType to newType',
migrate: {
async document(doc, context) {
if (doc._type === 'oldType') {
// Create new document with new type
const newDoc = {
...doc,
_type: 'newType',
_id: doc._id.replace('drafts.', ''), // or generate new ID
}
await context.client.create(newDoc)
// Delete old document
await context.client.delete(doc._id)
}
}
}
})You can also write a custom script using the Sanity client:
import {createClient} from '@sanity/client'
const client = createClient({
projectId: 'your-project-id',
dataset: 'your-dataset',
token: 'your-token',
apiVersion: '2024-01-01',
useCdn: false
})
const oldDocs = await client.fetch(`*[_type == "oldType"]`)
for (const doc of oldDocs) {
const {_id, _rev, _updatedAt, _createdAt, ...content} = doc
// Create new document with new type
await client.create({
...content,
_type: 'newType',
_id: _id, // Keep same ID or generate new one
})
// Delete old document
await client.delete(_id)
}_id values if you delete the old documents first, or generate new IDs if you want to keep both temporarily_iddrafts.)While you're preparing your migration, you can temporarily add the old type back to your schema (just the basic structure) so you can access those documents in Studio. This gives you time to plan and execute the migration properly.
The key takeaway: changing _type requires creating new documents, not modifying existing ones. It's a full data migration rather than a simple update, but the CLI migration tool makes this process much more manageable.
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