Cannot delete translation document due to self-reference from base document
The error you're seeing is a known issue with the @sanity/document-internationalization plugin. The plugin creates strong references between translated documents by default, and Sanity's API prevents deletion of documents that have strong references pointing to them to maintain referential integrity.
The Proper Solution: Use DeleteTranslationAction
The plugin provides a built-in DeleteTranslationAction document action specifically designed to handle this. This action removes the translation reference before deleting the document, which is the recommended approach.
To use it:
- Make sure the
DeleteTranslationActionis enabled in your Studio configuration (it should be by default) - In Sanity Studio, open the document you want to delete
- Look for the delete action in the document menu - it should handle the reference cleanup automatically
- The action will remove the translation metadata reference first, then delete the document
Alternative: Configure Weak References
If you want to prevent this issue going forward, you can configure the plugin to use weak references instead of strong references. Add this to your plugin configuration:
documentInternationalization({
supportedLanguages: [
{ id: "en", title: "English" },
{ id: "es", title: "Spanish" }
],
schemaTypes: ["yourDocumentType"],
weakReferences: true // Defaults to false
})Important: This setting only affects newly created translation relationships. For existing documents with strong references, you'll still need to use the DeleteTranslationAction or manually remove the references.
Why the CLI Delete Failed
The sanity documents delete CLI command doesn't automatically handle the translation reference cleanup, which is why it gave you the same error. The DeleteTranslationAction in Studio is specifically designed to handle this workflow.
Manual Workaround (If Needed)
If you need to delete documents programmatically or the DeleteTranslationAction isn't available, you'll need to:
- First, manually remove the reference from the parent document (
ElLnRMEzVGBvCslc1mXoT) - Then delete the translation document (
ElLnRMEzVGBvCslc1mXoT__i18n_es)
You can do this via the API or by editing the document in Studio to remove the translation metadata field before deletion.
The weakReferences: true configuration is the best long-term solution to avoid this issue, but for your immediate problem with existing documents, use the DeleteTranslationAction provided by the plugin in Studio.
Show original thread16 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.