Troubleshooting removing a deprecated field from a dataset in Sanity.io.
22 replies
Last updated: Apr 16, 2024
F
Hi,I'm looking for a efficient way to remove a deprecated field from a Dataset. I have tried executing this
script and tried with a migration script with an unset(). I not having any success atm. What is the best practice when you want to batch remove a field from a dataset.
script and tried with a migration script with an unset(). I not having any success atm. What is the best practice when you want to batch remove a field from a dataset.
Apr 15, 2024, 8:41 PM
That script may be giving you problems because it’s still using V2 syntax. That said, it’s overall still the best method for deleting data once corrected.
You can also just
deprecate the field in the UI if you don’t need to delete it.
You can also just
deprecate the field in the UI if you don’t need to delete it.
Apr 15, 2024, 8:48 PM
F
Is the v3 syntax uses cliClient or createClient constructor? I was able to make it run but, even if I am logged as admin, I get permission errors.
Apr 15, 2024, 8:58 PM
This is how you get the client for a script:
To execute the command you’ll need to use the flag
import {getCliClient} from 'sanity/cli' const client = getCliClient()
--with-user-token.
Apr 15, 2024, 9:14 PM
F
I'm getting the following error with
sanity exec scripts/batchRemoveField.js --with-user-token
details: { description: 'Mutation failed: Insufficient permissions; permission "manage" required', items: [ [Object] ], type: 'mutationError' }
Apr 15, 2024, 9:37 PM
F
thank you for your time ❤️
Apr 15, 2024, 9:38 PM
F
yes!
Apr 15, 2024, 9:49 PM
F
User type or user role?
Apr 15, 2024, 9:51 PM
F
User role: 'administrator'
Apr 15, 2024, 9:52 PM
F
but user type is at normal
Apr 15, 2024, 9:52 PM
Is it possible you’re logged into a different account that doesn’t have access to this project? This can happen if you use a different provider to log in than the one you used when you created the project.
Apr 15, 2024, 9:53 PM
F
hmm, I only have 1 account setup. I don't use email/password to login. No specific provider
Apr 15, 2024, 9:59 PM
It could have happened accidentally if you used something like Google instead of Github to log in, for example.
Apr 15, 2024, 10:01 PM
F
the project was created when we were still using Google provider. We have migrated to Microsoft this year and we switched to email/password on Sanity
Apr 15, 2024, 10:03 PM
F
I have no problem to read but it won't allow me to manage/write. I will ask a colleague in the morning to run the script on his account. I will update this tread then. Thanks again for your time
Apr 15, 2024, 10:09 PM
F
Good morning rd,We have tried a few things this morning but even my manager receives the same
403 forbiddenerror. I have tried to also add option in the
getCliClientconstructor like a new token created with
EDITORpermissions and the results are the same. Is there something I did not think about to try ? Thank you.
Apr 16, 2024, 2:31 PM
F
Hi again! I was able to make it work! I did update the CLI and also modified my initial GROQ query. It seem I was also fetching items that we are unable to modify. For my current use case, the script works now. Thank you soo much for your time helping me debug and rubber duck me out of there.
Apr 16, 2024, 6:47 PM
F
I suggest maybe updating the initial script. It is the first to pop up in google when you re searching for remove field in sanity. It could help more people.
Apr 16, 2024, 6:58 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.