这是一个错误返回在邮递员,当我试图存档记录在我的帆后端。
id**.:新记录的初始数据无效。\nDetails:\n无法使用所提供的新记录之一:必需属性UsageError的缺失值期望一个字符串,但相反,得到:未定义\n参见以获得帮助
请有人知道这个错误意味着什么吗?提前谢谢。
感谢您的响应,我的代码:-在控制器:
try {
await Laboratory.archive({id: inputs.id});
} catch (error) {
console.log('Error-6 CORE-DELETE_LABORATORY:', error)
exits.failed(`Error-6 CORE-DELETE_LABORATORY: ${error}${inputs.id}`)}在file config/models.js s.js中:
module.exports.models = {
migrate: 'alter',
fetchRecordsOnUpdate: true,
fetchRecordsOnCreate: true,
fetchRecordsOnCreateEach: true,
attributes: {
createdAt: { type: 'ref', columnType: 'datetime', autoCreatedAt: true, },
updatedAt: { type: 'ref', columnType: 'datetime', autoUpdatedAt: true, },
id: { type: 'string', columnName: '_id' },
},
dataEncryptionKeys: {
default: 'dRYQHBf8Zpza2vMS5BB3qcSiLspJP4BG37I2JkP2yYw='
},
cascadeOnDestroy: true
};实验室模型:
module.exports = {
attributes: {
type: {
type: 'string',
isIn: ['INSIDE', 'OUTSIDE'],
required: true,
},
raisonSocial: {
type: 'string',
required: true,
unique: true,
},
city: {
type: 'string'
},
address: {
type: 'string'
},
email: {
type: 'string'
},
neighborhood: {
type: 'string'
},
contacts: {
type: 'string'
},
logo: {
type: 'string'
},
lat: {
description: 'Latitude',
type: 'number'
},
long: {
description: 'Longitude',
type: 'number'
},
website: {
type: 'string',
defaultsTo: ''
},
subdomain: {
type: 'string',
unique: true,
required: true,
},
mobileMoney: {
type: 'string'
},
bank: {
type: 'string',
defaultsTo: ''
},
bankAccountID: {
type: 'string',
defaultsTo: ''
},
validated : {
type: 'boolean',
defaultsTo : false
},
f_establishment: {
model: 'establishment'
},
director: {
description: 'Chef of laboratory id',
type: 'json',
example: '{name, phone, role}',
required: true,
}
},
customToJSON () {
if (this.logo) {
this.logo = `${process.env.BASE_URL}/avatar/${this.logo}`
}
return this
}
};谢谢。
发布于 2020-10-19 06:40:47
当我们以不正确的方式使用db方法时,Sails会抛出UsageError。更准确地说,这就是Sails在其文档中所包含的内容。
当错误名为“UsageError”时,这表示水线方法被错误地使用,或者使用无效的选项执行(例如,试图创建一个违反模型高级验证规则的新记录)。
https://sailsjs.com/documentation/concepts/models-and-orm/errors#?usage-errors
为了给出一个简单的例子,如果您有一个带有极限参数的db查询,并且开始传递该参数的字符串值,那么Sails就会开始抛出UsageError。
在你的例子中,事情应该从错误细节本身自我解释。当undefined inputs.id试图运行Laboratory.archive({id: inputs.id})时,您的代码流将获得config/models.js,但如果您看到config/models.js,则希望id是一个字符串。
只需做一个基本的调试,以了解为什么inputs.id会以未定义的方式出现,并解决这个问题,您应该会做得很好。
https://stackoverflow.com/questions/61908471
复制相似问题