我无法连接到Postgres数据库

时间:2019-06-01 15:50:20

标签: node.js postgresql express sequelize.js

尝试连接数据库时

我的connectig属性:

const sequelize = new Sequelize("postgres", "postgres", "postgres", {
  dialect: "postgres",
  host: "127.0.0.1",
  port: "5432",
});   

服务器设置: enter image description here

错误:

{ SequelizeConnectionError: ������������ "postgres" �� ������ �������� ����������� (�� ������)
    at connection.connect.err (E:\Dropbox\BigDeal\BigDealExpressJSTest\node_modules\sequelize\lib\dialects\postgres\connection-manager.js:182:24)
    at Connection.connectingErrorHandler (E:\Dropbox\BigDeal\BigDealExpressJSTest\node_modules\pg\lib\client.js:174:14)
    at Connection.emit (events.js:189:13)
    at Socket.<anonymous> (E:\Dropbox\BigDeal\BigDealExpressJSTest\node_modules\pg\lib\connection.js:126:12)
    at Socket.emit (events.js:189:13)
    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: 'SequelizeConnectionError',

如何解决?

1 个答案:

答案 0 :(得分:0)

我前一段时间只使用过Sequelize,但这就是我初始化它的方式。

const sequelize = new Sequelize({
    database: 'project-db',
    username: 'postgres',
    password: 'postgres',
    host: 'localhost',
    port: 5432,
    dialect: 'postgres'
});

编辑:

阅读Sequelize文档,看来您的连接方式也应该有效。您确定“ postgres”(第一个参数)是现有数据库的名称吗?