运行
sequelize db:migrate
打印出来:
Sequelize [Node: 6.9.4, CLI: 2.4.0, ORM: 3.24.6]
Loaded configuration file "config\development.json".
Unable to connect to database: SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306
然后看看config / development.json,我看到了:
{
"development": {
"username": "postgres",
"password": "password",
"database": "mydb",
"host": "127.0.0.1",
"port": "5432",
"dialect": "postgres"
},
"test": {
"username": "postgres",
"password": "password",
"database": "mydb",
"host": "127.0.0.1",
"port": "5432",
"dialect": "postgres"
},
"production": {
"username": "postgres",
"password": "password",
"database": "mydb",
"host": "127.0.0.1",
"port": "5432",
"dialect": "postgres"
}
}
为什么呢?为什么sequelize仍然试图去mysql端口? ialso添加了端口,如配置文件中所示。我找不到任何资源说不支持postgres。但似乎sequelize-cli仍然不关心我在配置文件中输入的方言甚至端口号。
答案 0 :(得分:1)
您的NODE_ENV
似乎与development
,test
或production
不同,因为如果它与任何一个匹配,您将获得类似
Loaded configuration file "config/development.json".
Using environment "development".
Unable to connect to database: SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306
但是,在您的情况下,它不会打印它使用的环境,因此它表示您的development.json
文件中没有。您可以尝试使用
sequelize db:migrate --env development
根据sequelize-cli
源代码,它使用getEnvironment
方法获取env变量,如下所示:
getEnvironment: function () {
return args.env || process.env.NODE_ENV || 'development';
}
如果您未传递--env
参数,则需要当前NODE_ENV
。这意味着你的不同。