The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
I have a model "Activity" in my schema definition. I created several records in the database. Now, I wanted to add a property to the model "hasOpenTasks". I wanted to add a secondary index to this property so I had to add the .required() option to it. However, I have a lot of records where this field is missing. I want Amplify to treat it with the value "false" per default (i.e., hasOpenTasks: a.string().required().default("false")). However, when I retrieve data from the table I receive the following error:
I need a way to add required fields later to the project.
My recommendation is to raise an exception when you add a field to the model which is required but doesn't have a default value.
I guess for now, I need to manually add the field to each record by running a script.
If it is not possible to add a "default" value for new required fields, I appreciate any functionality that applies changes to existing records when I add required fields so I do not need to run scripts manually.
Hey @cabcookie, Thanks for bringing this up. It makes sense to update existing records when adding a default for a required field. I'll review this with the engineering team and get back to you.
Environment information
Data packages
Description
I have a model "Activity" in my schema definition. I created several records in the database. Now, I wanted to add a property to the model "hasOpenTasks". I wanted to add a secondary index to this property so I had to add the
.required()
option to it. However, I have a lot of records where this field is missing. I want Amplify to treat it with the value "false" per default (i.e.,hasOpenTasks: a.string().required().default("false")
). However, when I retrieve data from the table I receive the following error:I need a way to add required fields later to the project. My recommendation is to raise an exception when you add a field to the model which is required but doesn't have a default value. I guess for now, I need to manually add the field to each record by running a script. If it is not possible to add a "default" value for new required fields, I appreciate any functionality that applies changes to existing records when I add required fields so I do not need to run scripts manually.