πŸ‘€ Our most exciting product launch yet πŸš€ Join us May 8th for Sanity Connect

Issue with schema changes causing data to disappear and difficulty in deleting specific schema documents.

10 replies
Last updated: Aug 11, 2023
Hello! I had data in my schema, changed the schema up to the point where it seems to have turned into a new schema and now I can not see the data anymore. Is there a way to delete only all data for specific schema documents?
Aug 11, 2023, 12:58 PM
Not sure if I fully understand your issue. If you created a document with the older schema and then removed the field(s) in the new schema, when you open it in the studio, you should see the error
Unknown field found
like in the attached screenshot.
Aug 11, 2023, 1:28 PM
Unfortunately I do not, I made slight changes to one schema that had data. The data wasn't showing anymore so I thought it was deleted. When I run the frontend, the query is showing old data that is not showing on the studio. When I try to visit the page, it can't be generated, same with the new schema. I am going to try to delete all the data from the CLI for just that schema. Having trouble with that too, when I run documents query to check the IDs to delete, it comes back as an empty array when it definitely has data in it. I'll try figure it out.
Aug 11, 2023, 1:49 PM
By data, do you mean the entire document or just certain fields? Can you see if you can pull that data using groq in the vision plugin ?
*[_type == 'your-schema-name-here']{
  _id,
  ...,
}
If you are able to get back the ID, then you should be able to delete the data using
the client .
Aug 11, 2023, 1:54 PM
Fixed the problem, very sorry. I changed the schema name from projects to project and understand now how to properly use the CLI and vision to not make that mistake again. That was a lot of hours, thank you for the replies! Highly and heavily appreciated!
Aug 11, 2023, 2:44 PM
happy to help :) glad that your issue is sorted!
Aug 11, 2023, 2:48 PM
When I changed the schema name from projects to project, did it delete the schema? Or is it still there? Yeah they're, tried that in vision, so meaning that schema still exists. Would I need to change the name back, delete the contents, then change the schema name again? Cause the data is there but the studio does not have the schema for me to view or manipulate.
Aug 11, 2023, 2:51 PM
You can perhaps grab the
_id
of the documents using groq in Vision and then delete them using the API like I mentioned earlier ?

... data is there but the studio does not have the schema for me to view or manipulate.
I wonder if you can even access them via the URL in your Studio and delete them from there, something like:
<http://localhost:3333/desk/projects;id-of-the-document-here>
Erm.. does not look like you can do this URL trick unfortunately.
Aug 11, 2023, 3:01 PM
No you can't, excuse, constantly thinking what to do and how to do it. Many ways to fix the problem, and the thought of the best option is exhausting me. Thank you so much for your time, you're awesome! Would it be easy to migrate the data inside of projects to project? Even if I did that, there're so many components querying using that "s". I'll do it anyways, whether I can transfer the data or not.
Aug 11, 2023, 3:10 PM
This may be another option you could potentially explore where you export-&gt;reshape-&gt;import your data.
Aug 11, 2023, 3:36 PM
I'll read through it, thank you. Learned a lot.
Aug 11, 2023, 3:37 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.

Was this answer helpful?