gpt4 book ai didi

node.js - Node Postgres SequelizeConnectionError : password authentication failed for user

转载 作者:行者123 更新时间:2023-12-03 22:36:27 25 4
gpt4 key购买 nike

我正在使用 node 和 sequelize 开发后端应用程序。我的数据库来自 postgresql。

启动应用程序时,数据库连接工作正常,但当它尝试与数据库通信以读取或更新时,它会失败并出现连接错误:
用户“wushin”的密码验证失败。

对我来说似乎真的很奇怪,因为数据库连接已经完成,并且密码已经过验证。你们知道发生了什么吗?可能是 pg 模块的问题,但我尝试了不同的版本。

版本
Node :10.17.0
Sequelize :5.21.3
Postgres:10.11
pg模块:7.17.1

-> 此代码工作正常:

const sequelize = new Sequelize(process.env.DATABASE_DEV_URL)

sequelize
.authenticate()
.then(() => {
console.log('Connection has been established successfully.\n')
})
.catch(err => {
console.error('Unable to connect to the database:', err)
})

-> 但是这个 promise 因 SequelizeConnectionError 而失败:
models.Question.findAll()
.then(data => {
console.log('-> Succeeded data fetching\n')
console.log(data)
})
.catch(err => {
console.log('-> Failed data fetching\n')
console.log('Error', err)
})

日志:
yarn run v1.19.2
$ node index.js
Example app listening on port 4000 or something!
Executing (default): SELECT 1+1 AS result
Connection has been established successfully.

- Trying to fetch data:
-> Failed data fetching
Error:
{ SequelizeConnectionError: password authentication failed for user "wushin"
at connection.connect.err (/home/wushin/Projects/GuessGame/theguessgame-api/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:182:24)
at Connection.connectingErrorHandler (/home/wushin/Projects/GuessGame/theguessgame-api/node_modules/pg/lib/client.js:194:14)
at Connection.emit (events.js:198:13)
at Socket.<anonymous> (/home/wushin/Projects/GuessGame/theguessgame-api/node_modules/pg/lib/connection.js:128:12)
at Socket.emit (events.js:198:13)
at addChunk (_stream_readable.js:287:12)
at readableAddChunk (_stream_readable.js:268:11)
at Socket.Readable.push (_stream_readable.js:223:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
name: 'SequelizeConnectionError'

最佳答案

您似乎没有将任何配置传递给 Sequelize但主人。最低配置是主机、端口、数据库名称、方言用户名和密码。

从文档:

 const Sequelize = require('sequelize');

// Option 1: Passing parameters separately const sequelize = new
Sequelize('database', 'username', 'password', {
host: 'localhost',
dialect: /* one of 'mysql' | 'mariadb' | 'postgres' | 'mssql' */
});

// Option 2: Passing a connection URI const sequelize = new
Sequelize('postgres://user:pass@example.com:5432/dbname');

关于node.js - Node Postgres SequelizeConnectionError : password authentication failed for user,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59696141/

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