How AI is powering better personalization in e-commerce [with Vercel]. Sign up now

Error: Cannot publish document due to references - how to force publish?

18 repliesLast updated: Dec 2, 2025

Hi. I am getting an error when trying to publish a document.

Mutation(s) failed with 1 error(s): - Document "drafts.4d463db7-9140-46d0-94b4-2801c195c202" cannot be deleted as there are references to it from "69ebe839-9dd3-4e9b-be38-0da662df7973"

I’m new to Sanity and picking up an existing client project. I have upgrade to the latest version of Sanity, but still get the same issue and I am unsure what else to try at this stage. Is there a way to force publish? I am not going to go through and detach this document reference from hundreds of pages so there must be some other way?
AI Update

I understand your frustration - this error is indeed preventing you from publishing, and it's a referential integrity issue that needs to be properly resolved. Let me explain what's actually happening and provide you with real solutions.

What's Actually Happening

The error message tells you that document 69ebe839-9dd3-4e9b-be38-0da662df7973 contains a strong reference pointing to your draft (drafts.4d463db7-9140-46d0-94b4-2801c195c202). When you try to publish, Sanity attempts to delete the draft document (as part of the normal publish process), but strong references enforce referential integrity - they prevent deletion of documents that other documents depend on.

This is blocking your publish operation completely.

Why This Happened

Someone created a reference to your draft document instead of the published version. This typically happens when:

Solution 1: Fix the Referencing Document

The cleanest approach is to update document 69ebe839-9dd3-4e9b-be38-0da662df7973 to reference the published version instead:

If you need to do this for multiple documents, you could write a migration script to update all references from drafts.4d463db7-9140-46d0-94b4-2801c195c202 to 4d463db7-9140-46d0-94b4-2801c195c202.

Solution 2: Convert to Weak References (Requires Migration)

As explained in the Sanity weak references documentation, weak references allow documents to be deleted even when other documents reference them. However, simply adding weak: true to your schema won't fix existing data.

You need to:

{
  name: 'myReferenceField',
  type: 'reference',
  to: [{type: 'yourDocumentType'}],
  weak: true  // This only affects NEW references
}
// Example migration using Sanity client
const doc = await client.getDocument('69ebe839-9dd3-4e9b-be38-0da662df7973')
// Find the reference field and update it
const updatedDoc = {
  ...doc,
  yourReferenceField: {
    _type: 'reference',
    _ref: 'drafts.4d463db7-9140-46d0-94b4-2801c195c202',
    _weak: true  // Add this property
  }
}
await client.createOrReplace(updatedDoc)

Solution 3: Temporarily Remove the Reference

If the reference isn't critical:

Finding All Problematic References

If you suspect this affects hundreds of pages, you can use GROQ to find all documents referencing your draft:

*[references("drafts.4d463db7-9140-46d0-94b4-2801c195c202")]

Run this in the Vision plugin in your Studio to see the full scope of the issue.

Preventing This in the Future

To prevent references to drafts, add a filter to your reference fields in the schema:

{
  name: 'myReferenceField',
  type: 'reference',
  to: [{type: 'yourDocumentType'}],
  options: {
    filter: '!(_id in path("drafts.**"))'  // Only allow published documents
  }
}

Why There's No "Force Publish"

Sanity doesn't offer a force publish option because it would create broken references throughout your dataset, violating data integrity. The system is protecting you from creating orphaned references that would cause issues downstream.

The good news is that once you fix the referencing document(s) using one of the solutions above, your publish should work normally.

Show original thread
18 replies

Was this answer helpful?

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.

Related contributions