Reputation: 477
I am trying to update a table through sequelize. but I am getting error-Unhandled rejection SequelizeDatabaseError: Unknown column 'NaN' in 'field list' . My code is
db.billingplan.findById(req.params.id).then(result=>{
result.update({
'poregisterReference': String(req.body.reference),
'po_number' : req.body.po_number,
'billing_milestone': String(req.body.billing_milestone),
'billing_milestone_probable_date':checkDate(req.body.billing_milestone_probable_date),
'milestone_blling_amount':req.body.milestone_billing_amount,
'actual_billing_date': actual_billing_date,
'bill_number':req.body.bill_number,
'bill_amount':bill_amount,
'tax_rate':tax_rate,
'tds_rate':tds_rate,
'recovery_date': recovery_date,
'recovery_amount':recovery_amount ,
'utr_number': String(req.body.utr_number),
'bill_amount_with_tax': bill_amount_with_tax,
'net_recoverable_after_tds': net_recoverable_after_tds ,
'short_recovery': recovery_amount - net_recoverable_after_tds,
'recovery_period': dayDiff(recovery_date, actual_billing_date )
});
});
I have used this way to update without using where clause but never had this problem, so I am guessing thats not the problem. Can someone tell me what it is that I am doing wrong here. follwing is the stacktrace:
Unhandled rejection SequelizeDatabaseError: Unknown column 'NaN' in 'field list'
at Query.formatError (D:\Users\Temp\Desktop\POregister\node_modules\sequelize\lib\dialects\mysql\query.js:228:16)
at Query.connection.query [as onResult] (D:\Users\Temp\Desktop\POregister\node_modules\sequelize\lib\dialects\mysql\query.js:55:23)
at Query.Command.execute (D:\Users\Temp\Desktop\POregister\node_modules\mysql2\lib\commands\command.js:30:12)
at Connection.handlePacket (D:\Users\Temp\Desktop\POregister\node_modules\mysql2\lib\connection.js:515:28)
at PacketParser.onPacket (D:\Users\Temp\Desktop\POregister\node_modules\mysql2\lib\connection.js:94:16)
at PacketParser.executeStart (D:\Users\Temp\Desktop\POregister\node_modules\mysql2\lib\packet_parser.js:77:14)
at Socket.<anonymous> (D:\Users\Temp\Desktop\POregister\node_modules\mysql2\lib\connection.js:102:29)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:547:20)
Upvotes: 0
Views: 8760
Reputation: 768
What you should do is to check the values of what you set as FindOptions. I think one of them is NaN
. I had the same error.
NOTE i write my options in a variable and then print it.
let options = {
where: {},
limit: page?.limit ?? PHONE_LIMITATION,
attributes: [
Phone.col.id,
Phone.col.phone,
Phone.col.userId,
Phone.col.createdAt,
Phone.col.updatedAt,
],
offset: page?.offset ?? 0,
};
console.log(options);
// other stuff
Upvotes: 2
Reputation: 19
You might want to check how you defined associations of your tables ( hasOne(), belongsTo() etc). I defined unnecessary association somewhere in my code and had a similar problem. This introduces unwanted columns/attributes.
Upvotes: 1