How to Update Sanity Schema in Nextjs 15
A practical guide to updating your Sanity schema in modern Next.js 15 apps — simplified and developer-friendly.

Sanity.io is a powerful content management system with a flexible schema that lets you model your content exactly how you need it. However, when updating your schema, you might encounter issues that prevent you from deploying your changes. This guide walks you through the process of updating your Sanity schema and troubleshooting common problems.
When you modify your Sanity schema, you need to:
- Test your changes locally
- Deploy your schema to Studio
- Deploy your GraphQL API (if you're using GraphQL)
Common Schema Errors
Before deploying any changes, it's crucial to test them locally:
npx sanity dev
This command starts your local Sanity Studio and automatically checks your schema for errors. The development server provides immediate feedback about issues in your schema configuration.
Reference Errors
One of the most common issues occurs when one schema type references another that isn't properly defined or imported. For example:
// categoryType.ts with a reference error
export const categoryType = defineType({
name: 'category',
title: 'Category',
type: 'document',
fields: [
// ...other fields
defineField({
name: 'featuredArticles',
title: 'Featured Articles',
type: 'array',
of: [{ type: 'reference', to: [{ type: 'article' }] }],
// Error: 'article' type is referenced but not imported or defined
}),
],
});
How to Fix Reference Errors
Make sure to:
- Import all referenced types at the top of your schema file
- Register all schema types in your main schema index file
- Check for typos in type names
Corrected example:
// Import the referenced type
import { articleType } from './articleType';
export const categoryType = defineType({
name: 'category',
title: 'Category',
type: 'document',
fields: [
// ...other fields
defineField({
name: 'featuredArticles',
title: 'Featured Articles',
type: 'array',
of: [{ type: 'reference', to: [{ type: 'article' }] }],
// Now correct because 'article' type is imported
}),
],
});
Other Common Schema Issues
- Circular references: Two schema types that reference each other directly
- Naming conflicts: Multiple schema types with the same name
- Invalid field configurations: Using options that don't exist for a specific field type
- Missing required properties: Forgetting to include mandatory properties like
name
ortype
Deploying Schema Changes
Step 1: Deploy to Studio
Once your schema passes local validation, deploy it to your Sanity Studio:
npx sanity deploy
This makes your schema changes available in the hosted version of your Studio.
Step 2: Deploy GraphQL API (if applicable)
If you're using GraphQL with Sanity, you need to deploy your GraphQL API separately:
npx sanity graphql deploy --dataset production
If you encounter a SchemaError during GraphQL deployment, it means there are still issues with your schema that need to be fixed.
Troubleshooting Deployment Issues
Ensure You're in the Right Directory
Run all Sanity commands from the directory that contains your sanity.config.js
or sanity.config.ts
file:
# Check if you're in the right directory
ls -la sanity.config.ts
Check Current Project Context
To verify your project setup:
npx sanity debug
Reset GraphQL Deployment
If you're having persistent issues with GraphQL deployment:
# Force undeploy GraphQL
npx sanity graphql undeploy --force
# Then deploy again
npx sanity graphql deploy --dataset production
Getting More Error Details
Use the --verbose
flag to get more detailed error information:
npx sanity graphql deploy --dataset production --verbose
Schema Update Workflow Best Practices
- Make incremental changes: Update and test one schema type at a time
- Version control: Commit working versions before making major changes
- Test thoroughly: Check all affected parts of your content model in the Studio
- Be careful with destructive changes: Renaming or removing fields can lead to data loss
- Migrate data when needed: Use Sanity's migration tools for schema changes that affect existing data
Example: Adding a New Field to an Existing Schema
// Before
export const authorType = defineType({
name: 'author',
title: 'Author',
type: 'document',
fields: [
defineField({
name: 'name',
title: 'Name',
type: 'string',
}),
defineField({
name: 'bio',
title: 'Bio',
type: 'text',
}),
],
});
// After - adding a new social media field
export const authorType = defineType({
name: 'author',
title: 'Author',
type: 'document',
fields: [
defineField({
name: 'name',
title: 'Name',
type: 'string',
}),
defineField({
name: 'bio',
title: 'Bio',
type: 'text',
}),
defineField({
name: 'socialMedia',
title: 'Social Media Links',
type: 'array',
of: [
{
type: 'object',
fields: [
{ name: 'platform', type: 'string', options: { list: ['Twitter', 'LinkedIn', 'Instagram'] } },
{ name: 'url', type: 'url' },
],
},
],
}),
],
});
Conclusion
Updating your Sanity schema requires careful planning and testing. By following the steps outlined in this guide, you can make changes to your content model with confidence, minimize errors, and ensure a smooth deployment process. Remember that the local development environment is your best tool for catching issues early before they affect your production content.