#updating Schema: Schema validation failed

4 messages · Page 1 of 1 (latest)

ripe frost
#

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 optional

marsh willow
#

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

There are as many ways to migrate data as there are databases, but here’s some basic information to set the stage.

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.