【问题标题】:Updating error in sequelizesequelize 更新错误
【发布时间】:2015-07-16 20:37:42
【问题描述】:

这是什么错误?

Unhandled rejection SequelizeDatabaseError: ER_EMPTY_QUERY: Query was empty
    at Query.formatError (node_modules/sequelize/lib/dialects/mysql/query.js:159:14)
    at Query._callback (node_modules/sequelize/lib/dialects/mysql/query.js:35:21)
    at Query.Sequence.end (node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)
    at Query.ErrorPacket (node_modules/mysql/lib/protocol/sequences/Query.js:94:8)
    at Protocol._parsePacket (node_modules/mysql/lib/protocol/Protocol.js:274:23)
    at Parser.write (node_modules/mysql/lib/protocol/Parser.js:77:12)
    at Protocol.write (node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket.<anonymous> (node_modules/mysql/lib/Connection.js:96:28)
    at Socket.emit (events.js:107:17)
    at readableAddChunk (_stream_readable.js:163:16)
    at Socket.Readable.push (_stream_readable.js:126:10)
    at TCP.onread (net.js:538:20)

我正在尝试使用以下代码更新实体:

db.Account.update({
                    'post_id': data.id
                }, {
                  where: { id: account.id }
                })
                .spread(account => {

                  next();
                });

但它不起作用。有什么想法吗?

【问题讨论】:

  • 您确定该列名为post_id - 也许实际上是postId
  • 也出现这个错误,你有没有想出一些解决办法?
  • 听起来有些东西是未定义的。 data.id 或 account.id 未定义,无法创建查询。

标签: mysql sequelize.js


【解决方案1】:

我遇到了同样的问题,经过大量调试后发现了这个愚蠢的错误。我的原因是在 mysql 中添加了一个 column 并忘记将其添加到代表同一张表的 sequelize model 因此对于您的情况也建议您仔细检查post_id 存在于 Account sequelize 模型中。

【讨论】:

  • 我拼错了一个列名,因为没有正确大写字母(facepalm moment)——检查你的大小写和拼写!
  • 仅供参考 - 如果数据没有变化,则会出现此“查询为空”错误。参考-stackoverflow.com/questions/48061748/…
猜你喜欢
  • 2021-09-30
  • 1970-01-01
  • 1970-01-01
  • 2013-08-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-15
  • 2016-06-18
相关资源
最近更新 更多