我正在使用sequelize migrations。这是我的config.js:
require('dotenv').config()
module.exports = {
development: {
database: process.env.DEV_DATABASE,
host: process.env.DEV_HOST,
dialect: 'postgres'
},
test: {
database: process.env.TEST_DATABASE,
host: process.env.TEST_HOST,
dialect: 'postgres'
},
production: {
database: process.env.DATABASE_URL,
dialect: 'postgres'
},
}当我部署到heroku并运行:
heroku run npx sequelize-cli db:migrate我得到了错误:
Loaded configuration file "config/config.js".
Using environment "production".
ERROR: connect ECONNREFUSED 127.0.0.1:5432我尝试将我的配置更改为use_env_variable: DATABASE_URL,但得到了Error reading "config/config.js". Error: ReferenceError: DATABASE_URL is not defined
如果我使用console.log(process.env.DATABASE_URL)命令,我会得到类似这样的结果:
postgres://bczwqcbnwftivi:80bbc89546c0953e0ffd221a950cac249d25d4ef1812127054af7c2f504b2c39@ec2-54-225-205-79.compute-1.amazonaws.com:5432/d8gsvl0n8qilcs发布于 2019-09-27 02:24:09
这是可行的:
{
"development": {
"database": "products_api_development",
"dialect": "postgres"
},
"test": {
"database": "products_api_test",
"dialect": "postgres"
},
"production": {
"use_env_variable": "DATABASE_URL",
"dialect": "postgres",
"dialectOptions": {
"ssl": true
}
}
}https://stackoverflow.com/questions/58103296
复制相似问题