Error migrating data with CLI due to non-existent document reference
33 replies
Last updated: Jan 19, 2023
P
I have a singleton document set up following the guide here: https://www.sanity.io/guides/singleton-document
When I attempt to migrate data from staging to production using the CLI with
The only reference to this document is in the desk structure per that guide. Is there a way to get around this? I’m also confused because
When I attempt to migrate data from staging to production using the CLI with
--replace, I get the following error:
sanity:client [589] Response body: { "error": { "description": "Mutation(s) failed with 1 error(s)", "items": [ { "error": { "description": "Document \"landingPage\" references non-existent document \"6e064ed9-c668-4084-a803-8166a5a970f1\"", "id": "landingPage", "referenceID": "6e064ed9-c668-4084-a803-8166a5a970f1", "type": "documentReferenceDoesNotExistError" }, "index": 0 } ], "type": "mutationError" }
landingPageis not any of our types
Jan 19, 2023, 5:53 PM
It looks like the document with
_id: landingPageis referencing a document that doesn’t exist in the new dataset. What does that landing page document look like?
Jan 19, 2023, 6:28 PM
P
import { DocumentDefinition } from "sanity" export const etaLanding2021: DocumentDefinition = { name: "etaLanding2021", type: "document", title: "ETA 2021 Landing", preview: { prepare: () => ({ title: "ETA 2021 Landing Page", }), }, groups: [ { name: "pageData", title: "Page Data", default: true, }, { name: "seo", title: "SEO", }, ], fields: [ { type: "seo", group: "seo", name: "seo" }, { title: "hero banner logo", name: "heroImage", type: "reference", to: [{ type: "reusableImage" }], group: "pageData", }, { type: "string", title: "Youtube video (ID)", name: "youtubeVideoId", group: "pageData", }, { type: "image", title: "Youtube video Poster image", name: "youtubeVideoPoster", group: "pageData", }, ], }
Jan 19, 2023, 6:29 PM
P
oooooooo
Jan 19, 2023, 6:29 PM
P
the reusable image
Jan 19, 2023, 6:29 PM
P
🤦♂️
Jan 19, 2023, 6:29 PM
P
hm interesting, moving that over also failed with a mutation error
Jan 19, 2023, 6:33 PM
P
but that reusable image has no references
Jan 19, 2023, 6:33 PM
P
it seems to re-trigger that same landing page error
Jan 19, 2023, 6:34 PM
P
when i try to import only the re-usable image types
Jan 19, 2023, 6:34 PM
P
this does include assets, yes
Jan 19, 2023, 6:34 PM
P
in all of the imports in question
Jan 19, 2023, 6:34 PM
P
[ 0%] Strengthening references (4.70s) sanity:client [588] Response code: 409 Conflict +267ms sanity:client [588] Response body: { "error": { "description": "Mutation(s) failed with 1 error(s)", "items": [ { "error": { "description": "Document \"landingPage\" references non-existent document \"6e064ed9-c668-4084-a803-8166a5a970f1\"", "id": "landingPage", "referenceID": "6e064ed9-c668-4084-a803-8166a5a970f1", "type": "documentReferenceDoesNotExistError" }, "index": 0 } ], "type": "mutationError" } } +0ms
Jan 19, 2023, 6:35 PM
Can you try adding the
--allow-failing-assetsflag to see if the assets may be the issue?
Jan 19, 2023, 6:36 PM
P
Same error
Jan 19, 2023, 6:38 PM
P
I also tried re-publishing the doc with that field blank to hopefully “remove” the reference but the vision tool confirms it is still there
Jan 19, 2023, 6:38 PM
P
oh hmm. it seems like the singleton setup isn’t actually showing me the broken document.. it allowed me to create a new one
Jan 19, 2023, 6:39 PM
P
ok, well this is going to take some cleanup
Jan 19, 2023, 6:40 PM
P
ok, all set
Jan 19, 2023, 6:58 PM
P
ok.. so not quite all set here. No matter what, this error seems to pop up
Jan 19, 2023, 7:23 PM
P
I have deleted the singleton “landingPage” document from production and am just trying to migrate over the reusable images first.. but I always get that same error when moving over the reusable images
Jan 19, 2023, 7:24 PM
P
even there are no landing page docs at all
Jan 19, 2023, 7:24 PM
P
it seems to get pulled in to the import with the reusable images for some reason?
Jan 19, 2023, 7:24 PM
P
and the reusable images don’t actually import
Jan 19, 2023, 7:25 PM
P
for some reason, when the assets get imported that document is created no matter what.. I think maybe because there is an asset (image) field in the document?
Jan 19, 2023, 7:29 PM
P
I confirmed the NDJson does not have the data for that document in it.. so somehow the data gets there via the assets json
Jan 19, 2023, 7:30 PM
P
in the studio I get a warning about strong vs weak references:
Jan 19, 2023, 7:33 PM
P
if I explicitly set weak to true in the schema it goes away. I did not have this specified before
Jan 19, 2023, 7:35 PM
P
ok well, I have no idea how I pulled it off but I got all the data over there. I think the key was throwing in a
--rawexport at some point along the way - this got the reusable image documents there but none of the assets associated (the image field in all docs was blank)
Jan 19, 2023, 7:45 PM
P
I also then had to change that field above to be strong, again, in the production dataset
Jan 19, 2023, 7:46 PM
I think that weak reference may have been happening because the import was failing while strengthening references.
Jan 19, 2023, 7:48 PM
Sanity– build remarkable experiences at scale
Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.