未处理的拒绝SequelizeDatabaseError:'字段列表'中的未知列'NaN'

时间:2018-01-15 08:39:33

标签: node.js sequelize.js

我正在尝试通过sequelize更新表格。但我收到错误 - 未处理拒绝SequelizeDatabaseError:'字段列表'中的未知列'NaN'。我的代码是

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

我使用这种方式更新而不使用where子句但从来没有遇到过这个问题,所以我猜这不是问题所在。有人能告诉我这里我做错了什么。 以下是堆栈跟踪:

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)

2 个答案:

答案 0 :(得分:1)

您可能想检查如何定义表的关联(hasOne(),belongsTo()等)。我在代码中的某处定义了不必要的关联,并且遇到了类似的问题。这会引入不需要的列/属性。

答案 1 :(得分:1)

您应该做的是检查您设置为 FindOptions 的值。我认为其中之一是 NaN。我有同样的错误。

As you can seed it offset is NaN

注意我将我的选项写在一个变量中,然后打印出来。

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