Issue creating a document in Sanity Studio due to invalid schema

10 replies
Last updated: Feb 27, 2023
Hi! When I create a document in sanity studio, I met some issue.
This document has the schema type *, which is not defined as a type in the local content studio schema.
Let me know any hint please.
Thanks for your time.
🎉
AI Update

This error happens when you have a document in your Content Lake that references a schema type that doesn't exist in your current Studio configuration. The asterisk (*) in the error message is a placeholder for the actual schema type name.

Here are the most common causes and solutions:

1. Missing schema type in your config

The schema type needs to be defined and registered in your sanity.config.js file. Check that you've included the schema type in your configuration:

import { defineConfig } from 'sanity'
import { deskTool } from 'sanity/desk'
import mySchemaType from './schemas/mySchemaType' // Import your schema

export default defineConfig({
  // ... other config
  schema: {
    types: [mySchemaType] // Make sure it's registered here
  }
})

2. Schema was removed but documents still exist

If you previously had a schema type defined and then removed it, documents of that type still exist in your dataset. You have two options:

  • Add the schema back: Re-add the schema type definition to your config
  • Delete the orphaned documents: Use the Management API or Vision plugin to find and delete documents with that type

3. Working across different branches/environments

If you're working with multiple developers or environments, someone may have created documents with a schema type that hasn't been synced to your local Studio yet. Pull the latest schema definitions from your repository.

4. Typo in the schema type name

Double-check that the name field in your schema definition matches exactly what's being referenced. Schema type names are case-sensitive.

To identify which specific schema type is causing the issue, you can use the Vision plugin to query your documents and see what types exist:

*[!(_id in path("_.**"))] | order(_type) { _type }

This will show you all document types in your dataset, helping you identify any mismatches with your local schema configuration.

Hope this helps! 🎉

Can you paste in your current schema?
sure
import {DocumentIcon} from '@sanity/icons';

import {validateSlug} from '../../utils/validateSlug';


export default {

name: 'page',

title: 'Page',

type: 'document',

icon: DocumentIcon,

groups: [

{

name: 'theme',

title: 'Theme',

},

{

default: true,

name: 'editorial',

title: 'Editorial',

},

{

name: 'seo',

title: 'SEO',

},

],

fields: [

// Title

{

name: 'title',

title: 'Title',

type: 'string',

validation: (_Rule_) _=>_
_Rule_.required(),

},

// Slug

{

name: 'slug',

type: 'slug',

options: {source: 'title'},

validation: validateSlug,

},

// Color theme

{

name: 'colorTheme',

title: 'Color theme',

type: 'reference',

to: [{type: 'colorTheme'}],

group: 'theme',

},

// Show hero

{

name: 'showHero',

title: 'Show hero',

type: 'boolean',

description: 'If disabled, page title will be displayed instead',

initialValue: false,

group: 'editorial',

},

// Hero

{

name: 'hero',

title: 'Hero',

type: 'hero.page',

hidden: ({_document_}) _=>_ !_document_?.showHero,

group: 'editorial',

},

// Body

{

name: 'body',

title: 'Body',

type: 'body',

group: 'editorial',

},

// SEO

{

name: 'seo',

title: 'SEO',

type: 'seo.page',

group: 'seo',

},

],

preview: {

select: {

active: 'active',

seoImage: 'seo.image',

title: 'title',

},

prepare(_selection_) {

_const_ {seoImage, title} = _selection_;


return {

media: seoImage,

title,

};

},

},

};
Did you get to desk tool without problems? And when you encounter the issue only when you click the New button to create a new
page
document?
It looks to me that the schema is invalid.
Let me know in detail.
I mean, I tried this and I’m probably missing a few files or I’m just not sure about using
seo.image
for example whether that’s valid.
I think you have the schema there for
seo
correct? can you send it and the others?
I don't think it is issue. Would you like to try without that? Otherwise it is related to saved documents? There are 2 page documents already.
unfortunately, I can’t replicate your setup to the best of my abilities. with the schema you provided, I can’t run Sanity studio because there were errors

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?