2016-03-24 23 views
1

私は、アプリケーションののMySQLデータベースを使用していますSails.jsSails.js、Model.updateは()ER_BAD_FIELD_ERRORをスロー:不明な列には、 'where句'

にかなり新しいですで '未定義します'。

問題

私は( 'u_othersを' という名前)UPDATEテーブル にしようとしています、IAMが、次のエラーを取得:テーブルの

ER_BAD_FIELD_ERROR: Unknown column 'undefined' in 'where clause':

構造:

"u_others"enter image description here

Deatailed:

ERRORenter image description here

モデル:

"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" 
} 
} 

Please note : I have console.log() all the req.parameters and all contains value

答えて

2

ラインautoPK:falseを削除するか、次のようにのようなあなたのモデルの属性idを追加します。

id:{ 
    type:'integer', 
    primaryKey:true 
} 

または エラーが

+0

感謝@あなたのモデルに主キーid属性の欠如によるものであり、それは私のために働いたwaza007、[upvotedと受け入れ] –

関連する問題