updating Schema: Schema validation failed
I'm trying to update my schema by adding a required document type.
But unless I put
v.optional()
I get an error.
Do I have to make it optional4 Replies
The issue you see is that your existing data doesn't have the field, so it can't be required (yet). Options are to delete the invalid documents or update them.
The steps to update them look like:
1. Make it optional and push
2. Set a value for all documents
3. Make it required
Related posts: https://stack.convex.dev/intro-to-migrations
https://stack.convex.dev/migrating-data-with-mutations
Intro to Migrations
There are as many ways to migrate data as there are databases, but here’s some basic information to set the stage.
Migrating Data With Mutations
Using mutations to migrate data in Convex.
If you don't care about correctness while developing and want to just push the schema and update them manually on the dashboard, you can set
schemaValidation: false
in your schema definition, then push, update the data, then optionally turn schema validation back on.Schemas | Convex Developer Hub
Schema validation keeps your Convex data neat and tidy. It also gives you end-to-end TypeScript type safety!
thank you will look into it