[英]Sails.js, Model.update() throws ER_BAD_FIELD_ERROR: Unknown column 'undefined' in 'where clause'
我是Sails.js的新手
我正在使用MySQL數據庫的應用程序。
問題 :
當我嘗試更新表(名為' u_others ')時,我收到以下錯誤:
ER_BAD_FIELD_ERROR:'where子句'中的未知列'undefined':
表結構:
Deatailed:
型號:
“U_others.js”
module.exports = {
autoCreatedAt:false,
autoUpdatedAt:false,
autoPK:false,
attributes: {
username:{
type:"string",
unique:true
},
name:{
type:"string",
},
d_o_b:{
type: "string"
},
phone:{
type: "integer",
size: 15
},
gender:{
enum: ['m', 'f', 'other']
},
avatar:{
type: "string"
}
}
};
更新查詢
var other = req.param('other_details');
var wheree = {
username: username
};
var data = {
name: other.name,
d_o_b: other.d_o_b,
phone: other.phone,
gender: other.gender,
avatar: other.avatar
};
U_others.update({username: req.param('username')}, data)
.exec(function afterwards(err, updated){
if (err) {
return res.negotiate(err);
}
res.status(201);
res.json(updated);
});
請求參數體
{
"username": "xyz",
"other_details":{
"name": "xx yy zz",
"d_o_b": "2014-11-22",
"phone":88787878787,
"gender":"m",
"avatar":"sdfsdf/sdfsdfsdf/sdfsdf.jpg"
}
}
請注意:我有console.log()所有req.parameters,並且都包含值
刪除行autoPK:false
或在模型中添加屬性id
,如下所示。
id:{
type:'integer',
primaryKey:true
}
或錯誤是由於模型中缺少主鍵ID屬性
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.