创建模型

时间:2017-09-14 18:00:21

标签: javascript node.js sequelize.js

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

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:connect ECONNREFUSED 127.0.0.1:1337       at connection.connect.err(G:\ projects \ investcrypto \ node_modules \ sequelize \ lib \ dialects \ postgres \ connection-manager.js:95:24)       在Connection.connectingErrorHandler(G:\ projects \ investcrypto \ node_modules \ pg \ lib \ client.js:123:14)       在emitOne(events.js:115:13)       在Connection.emit(events.js:210:7)       在Socket。 (G:\项目\ investcrypto \ node_modules \ PG \ lib中\ connection.js:71:10)       在emitOne(events.js:115:13)       在Socket.emit(events.js:210:7)       在emitErrorNT(internal / streams / destroy.js:64:8)       at _combinedTickCallback(internal / process / next_tick.js:138:11)       at process._tickCallback(internal / process / next_tick.js:180:9)       name:'SequelizeConnectionRefusedError',       父:        {错误:连接ECONNREFUSED 127.0.0.1:1337          at Object.exports._errnoException(util.js:1024:11)          at exports._exceptionWithHostPort(util.js:1047:20)          在TCPConnectWrap.afterConnect [as oncomplete](net.js:1150:14)        代码:'ECONNREFUSED',        错误:'ECONNREFUSED',        系统调用:'connect',        地址:'127.0.0.1',        港口:1337},        原版的:        {错误:连接ECONNREFUSED 127.0.0.1:1337          at Object.exports._errnoException(util.js:1024:11)          at exports._exceptionWithHostPort(util.js:1047:20)          在TCPConnectWrap.afterConnect [as oncomplete](net.js:1150:14)        代码:'ECONNREFUSED',        错误:'ECONNREFUSED',        系统调用:'connect',        地址:'127.0.0.1',        port:1337}}

版本: npm:5.3.0 节点:8.2.1 续集:4.8.3 pg:7.3.0 pg-hstore 2.3.2

1 个答案:

答案 0 :(得分:0)

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

此外,Sequelize cli对于执行大量锅炉板代码非常有帮助

相关问题