在创build模型时产生连接错误

当我执行这个程序时,一切工作正常:

const Sequelize = require("sequelize"); const Conn = new Sequelize("data","postgresql","postgresql", { 'host' : "localhost", 'dialect' : "postgres", 'port' : "1337" }) // piece of code to be added here Conn.sync().then(function(){ console.log('DB connection sucessful.'); }, function(err){ console.log(err); }); 

控制台日志: DB connection successful. 当我添加这条线:

 const User = Conn.define('user', { firstName: { type: Sequelize.STRING }, lastName: { type: Sequelize.STRING } }); 

我得到这个错误消息:

{SequelizeConnectionRefusedError:连接ECONNREFUSED 127.0.0.1:1337在connection.connect.err(G:\ projects \ investcrypto \ node_modules \ sequelize \ lib \ dialects \ postgres \ connection-manager.js:95:24)Connection.connectingErrorHandler(G (events.js:210:7):emitOne(events.js:115:13):\ projects \ investcrypto \ node_modules \ pg \ lib \ client.js:123:14)。 (events.js:210:7)在emitOne(events.js:115:13)上的发射器(内部:G:\ projects \ investcrypto \ node_modules \ pg \ lib \ connection.js:71:10) / process / next_tick.js:180:9)在_combinedTickCallback(internal / process / next_tick.js:138:11)/streams/destroy.js:64:8)name:'SequelizeConnectionRefusedError',parent :错误:在位于TCPConnectWrap.afterConnect [ascomplete](net。)上的exports._exceptionWithHostPort(util.js:1047:20)处,在Object.exports._errnoException(util.js:1024:11)上连接ECONNREFUSED 127.0.0.1:1337。 js:1150:14)代码:'ECONNREFUSED',errno:'ECONNREFUSED',系统调用:'connect',地址:'127.0.0.1',端口:1337},original:{错误:连接ECONNREFUSED 127.0.0.1:1337 at在TCPConnectWrap.afterConnect [ascomplete](net.js:1150:14)处的exports.exceptionWithHostPort(util.js:1047:20)处的Object.exports._errnoException(util.js:1024:11)代码:'ECONNREFUSED', errno:'ECONNREFUSED',系统调用:'connect',地址:'127.0.0.1',端口:1337}}

版本:npm:5.3.0 node:8.2.1 sequelize:4.8.3 pg:7.3.0 pg-hstore 2.3.2

尝试使端口5432 。 这是postgres的默认端口。 确保数据库data是由用户postgresql创build的,密码确实是postgresql 。 根据数据库的创build方式,您可以将用户名和密码设置为null

另外, Sequelize cli对于做大量的锅炉代码真的很有帮助