Cannot delete locked image - document type no longer exists in schema

8 replies
Last updated: Jan 28, 2026
Hey everyone! I am updating an old studio for a client of mine and I need to delete some old images (using the media plugin).. However the sanity editor is not letting me delete the image because it is locked to an old document (document was named
editorialPage
which we no longer use). I went into my terminal and deleted the document manually using
sanity documents delete editoralPage
, but it says the document is not found.. Very odd. When I check the image reference it still says
A document of the unknown type editorialPage
... Any help with this? Ideally it would just be great to delete that document altogether
AI Update

It sounds like you're dealing with a document that's stuck in your dataset with an unknown/deleted document type! This is a common issue when you've removed a schema type from your Studio configuration but documents of that type still exist in your dataset.

The problem with sanity documents delete editorialPage is that the CLI command expects a document ID, not a document type name. Since the error says "A document of the unknown type editorialPage", the document likely has a different _id value (like editorialPage-123 or something similar).

Here are the proper ways to solve this:

Option 1: Find and Delete Using Vision Plugin

Go to your Sanity Studio and open the Vision plugin (the eye icon in the toolbar). Run this GROQ query:

*[_type == "editorialPage"]

This will show you all documents with that type, including their actual _id values. Note the IDs, then you can delete them using the CLI with the correct ID:

sanity documents delete "THE-ACTUAL-ID-HERE"

Remember to check for both published and draft versions - draft IDs have a drafts. prefix:

sanity documents delete "editorialPage-123"
sanity documents delete "drafts.editorialPage-123"

Option 2: Delete Programmatically Using Sanity Client

If you have multiple documents to delete, you can use the Sanity Client in a Node.js script:

import {createClient} from '@sanity/client'

const client = createClient({
  projectId: 'your-project-id',
  dataset: 'your-dataset',
  token: 'your-token-with-write-access',
  apiVersion: '2024-01-01',
  useCdn: false
})

// Query for all editorialPage documents
const docs = await client.fetch('*[_type == "editorialPage"]')

// Delete each one
for (const doc of docs) {
  await client.delete(doc._id)
  console.log(`Deleted ${doc._id}`)
}

Option 3: Use the HTTP Mutation API

You can also use the Mutation API directly with curl. First find the document IDs, then delete them:

curl -X POST \
  https://YOUR-PROJECT-ID.api.sanity.io/v2024-01-01/data/mutate/YOUR-DATASET \
  -H "Authorization: Bearer YOUR-TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "mutations": [
      {"delete": {"id": "THE-ACTUAL-DOCUMENT-ID"}}
    ]
  }'

About the Media Plugin Lock

Once you properly delete the document (and any draft versions), the media plugin should automatically unlock the image since there won't be any references pointing to it anymore. If it still shows as locked after deletion, try refreshing your Studio or checking if there are other documents referencing that image.

The Vision plugin approach is usually the quickest for finding these orphaned documents with unknown types. Let me know if you need help with any of these methods!

Show original thread
8 replies

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?