gpt4 book ai didi

node.js - 无法使用 sequelize : 'Column " 0"of relation "users"does not exists' 递增

转载 作者:搜寻专家 更新时间:2023-10-31 23:25:59 25 4
gpt4 key购买 nike

我使用 Sequelize 4.42.0 和 PostgreSQL 11.2 并努力使 increment 工作,我按照 documentation 中的描述进行操作.

我到处搜索,但找不到解决方案。我也尝试过:

await Users.update({ testIncrement: database.literal('testIncrement + 1') }, {
where: { id: user.id }
})

代码

Controller

export const test = async ({ body, user }, res) => {
try {
await Users.increment('testIncrement', { where: { id: user.id }})
} catch(error) {
console.log(error)
}
}

型号

const Users = database.define('users',
{
id: {
primaryKey: true,
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV4
},
testIncrement: {
defaultValue: 0,
type: Sequelize.INTEGER,
},
}
)

export default Users

预计

testIncrement 增加 1

结果

error: column "0" of relation "users" does not exist
at Connection.parseE (/Users/.../node_modules/pg/lib/connection.js:555:11)
at Connection.parseMessage (/Users/.../node_modules/pg/lib/connection.js:380:19)
at Socket.<anonymous> (/Users/.../node_modules/pg/lib/connection.js:120:22)
at Socket.emit (events.js:189:13)
at Socket.EventEmitter.emit (domain.js:441:20)
at addChunk (_stream_readable.js:284:12)
at readableAddChunk (_stream_readable.js:265:11)
at Socket.Readable.push (_stream_readable.js:220:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
name: 'error',
length: 121,
severity: 'ERROR',
code: '42703',
detail: undefined,
hint: undefined,
position: '35',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'analyze.c',
line: '2346',
routine: 'transformUpdateTargetList',
sql:
'UPDATE "users" SET "testIncrement"="testIncrement"+ 1,"0"=\'id\',"1"=\'testIncrement\',"2"=\'createdAt\',"3"=\'updatedAt\' WHERE "id" = \'adbe346a-b117-4f21-aa74-8a46d1ededae\' RETURNING *' }

最佳答案

好吧好新我发现是哪段代码造成了问题,坏新它似乎是 sequelize 的错误:

https://github.com/sequelize/sequelize/issues/8612

TL;DR - 在我的用户模型中删除它解决了这个问题

defaultScope: {
attributes: { exclude: ['password', 'email'] }
}

关于node.js - 无法使用 sequelize : 'Column " 0"of relation "users"does not exists' 递增,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56000198/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com