Siddhartha Chowdhury
Siddhartha Chowdhury

Reputation: 2734

Sails.js, Model.update() throws ER_BAD_FIELD_ERROR: Unknown column 'undefined' in 'where clause'

I am pretty new to Sails.js

I am using MySQL database for the application.

The problem:

When I am trying to UPDATE a table (named 'u_others') , Iam getting the following error:

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

Structure of table :

"u_others"enter image description here

Deatailed :

ERRORenter image description here

Model :

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

Update Query

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);
});

Request parameter body

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

Upvotes: 1

Views: 2740

Answers (1)

vkstack
vkstack

Reputation: 1664

remove the line autoPK:false or add an attribute id in your model like as follow.

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

or the error is due to absence of primary key id attribute in your model

Upvotes: 3

Related Questions