Error when publishing document with references to drafts preventing deletion
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:
- Documents are created/edited in draft mode and reference each other before publishing
- Custom code or migrations created references to draft IDs
- Initial values or programmatic mutations referenced drafts without using
_weak: true
Solutions (From Most to Least Recommended)
Solution 1: Fix the Referencing Document
The cleanest approach is to update document 69ebe839-9dd3-4e9b-be38-0da662df7973 to reference the published version instead:
- Open document
69ebe839-9dd3-4e9b-be38-0da662df7973in your Studio - Find the reference field pointing to
4d463db7-9140-46d0-94b4-2801c195c202 - Re-select the same document (this will update the reference to point to the published ID instead of the draft ID)
- Publish that document
- Now try publishing your original document
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:
- Update your schema to make the reference field weak:
{
name: 'myReferenceField',
type: 'reference',
to: [{type: 'yourDocumentType'}],
weak: true // This only affects NEW references
}- Migrate existing data to convert strong references to weak ones. According to the mutation documentation, weak references in mutations use
_weak: true:
// 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:
- Open document
69ebe839-9dd3-4e9b-be38-0da662df7973 - Remove the problematic reference temporarily
- Publish both documents
- Re-add the reference if needed
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.
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.