When I start server, it connects to database well.
In my case the command is nodemon
But when I try to migrate. the command is npx sequelize-cli db:migrate
I got connect ECONNREFUSED error.
I found that the problem was process.env If I put in the very string on username, password, database , host, it works well! but I think when migrate, It is not passed well I’m using dotenv how can I pass right config value..?
Any advice would be thankful.
This is my config file
require("dotenv").config();
module.exports = {
development: {
username: process.env.DEV_DATABASE_USER_NAME,
password: process.env.DEV_DATABASE_PASSWORD,
database: process.env.DEV_DATABASE_NAME,
host: process.env.DEV_DATABASE_HOST,
dialect: "mysql",
charset: "utf8",
collate: "utf8_general_ci",
operatorsAliases: false,
define: {
underscored: true
}
},
development_light: {
username: process.env.DEV_DATABASE_USER_NAME,
password: process.env.DEV_DATABASE_PASSWORD,
database: process.env.DEV_DATABASE_NAME,
host: process.env.DEV_DATABASE_HOST,
dialect: "mysql",
charset: "utf8",
collate: "utf8_general_ci",
operatorsAliases: false,
define: {
underscored: true
}
},
test: {
username: process.env.PROD_DATABASE_USER_NAME,
password: process.env.PROD_DATABASE_PASSWORD,
database: process.env.PROD_DATABASE_NAME,
host: process.env.PROD_DATABASE_HOST,
dialect: "mysql",
charset: "utf8",
collate: "utf8_general_ci",
operatorsAliases: false,
define: {
underscored: true
}
},
production: {
username: process.env.PROD_DATABASE_USER_NAME,
password: process.env.PROD_DATABASE_PASSWORD,
database: process.env.PROD_DATABASE_NAME,
host: process.env.PROD_DATABASE_HOST,
dialect: "mysql",
charset: "utf8",
collate: "utf8_general_ci",
operatorsAliases: false,
define: {
underscored: true
}
}
};
And this is error I got when I trying to migrate
Loaded configuration file "config/config.js".
Using environment "development".
(node:90780) [SEQUELIZE0004] DeprecationWarning: A boolean value was passed to options.operatorsAliases. This is a no-op with v5 and should be removed.
(Use `node --trace-deprecation ...` to show where the warning was created)
ERROR: connect ECONNREFUSED 127.0.0.1:3306