简体   繁体   English

postgreSQL错误:“约束不存在”(但确实存在……)

[英]postgreSQL error: “constraint does not exist” (but it does exist…)

I have a database that I'm trying to update, and I can't figure out why I'm getting this weird error about a column not existing. 我有一个要更新的数据库,但我不知道为什么我收到关于不存在的列的奇怪错误的信息。 When I access the database using 'heroku pg:psql' I can totally see the column though. 当我使用“ heroku pg:psql”访问数据库时,我完全可以看到该列。 I have found a couple other questions with similar issues, but haven't been able to resolve it. 我已经找到了几个其他的问题有类似的问题,但一直没能解决。

Here is my code to execute the INSERT...ON CONFLICT WITH CONSTRAINT...any ideas? 这是我的代码,用于执行INSERT ... ON CONFLICT WITH CONSTRAINT ...有什么想法吗?

const text = 'INSERT INTO "test2" '
+'(route_id, secupdated, retrievedate, traintimeday) '
+'VALUES($1, $2, $3, $4) '
+'ON CONFLICT ON CONSTRAINT traintimeday '
+'DO UPDATE SET (secupdated, secarrival) = (excluded.secupdated, excluded.secarrival) '
+'RETURNING *' ; 
const values = [train_id 
, Math.round(dateNow.getTime()/1000)
, Math.round(dateNow.getDate())
, Math.round(dateNow.getDate()) + stu.stop_id
]; 
pool.query(text, values, (err, res) => {
if (err) {
throw err;
}
console.log('user:', res.rows[0])
})

The error message says that 'constraint traintimeday does not exist' 错误消息说“约束traintimeday不存在”

If traintimeday is not a constraint, instead of: 如果traintimeday不是约束,则代替:

+'ON CONFLICT ON CONSTRAINT traintimeday '

use: 采用:

+'ON CONFLICT (traintimeday) '

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM