我有一个字段,我在模型中声明为字符串,如下所示:
App.Student= DS.Model.extend({
name: DS.attr('string'),
address1: DS.attr('string'),
address2: DS.attr('string'),
city: DS.attr('string'),
state: DS.attr('string'),
postal: DS.attr('string'),
country: DS.attr('string'),
});
Run Code Online (Sandbox Code Playgroud)
在编辑模式下,当我将Adderess 2字段更新为null时,则出现以下错误:
"Failed to edit property: One or more parameter values were invalid: An AttributeValue may not contain an empty string"
我知道这个错误是生成的,因为我将地址2字段更新为null并且我想要的地址2字段不是必需的(可以传递数据或者也可以将该列保留为空白")
如果您使用 DynamoDB(不是 DocumentClient),您可以像这样指定 null
const putItem: PutItemInput = {
TableName: `${process.env.PRIMARY_TABLE}`,
Item: {
key: { S: ${userId}` },
someField: { NULL: true }
}
}
Run Code Online (Sandbox Code Playgroud)
最后我得到了这个权利,方式可能有些不同,但它对我有用!
这是相同的代码。
AttributeUpdates: {
Address2:
{
Action: "DELETE"
},
}
Run Code Online (Sandbox Code Playgroud)
然后我根据条件添加值。
if (propertyObj.address2) {
params.AttributeUpdates.address2 = {
Value: {
S: propertyObj.address2
},
Action: "PUT"
}
}
Run Code Online (Sandbox Code Playgroud)
我衷心感谢所有试图帮助我的人,干杯!
归档时间: |
|
查看次数: |
14135 次 |
最近记录: |