问题
This is what I did
- require('dotenv').config() in the config file
- set .sequelizerc in the root directory like below
- set .sequelie file to point config, migrations, models, seeds directory from root directory
- ran
npx seuqlie-cli db:migrate
form root directory. It work! - ran
npx seuqlie-cli db:migrate
form sequelize directory. It doesn't read dotenv variable and come withconnect ECONNREFUSED 127.0.0.1:3306
and I want to know what is differences between 4 and 5..?
this is my directory looks like
my .sequlizerc file
const path = require('path')
module.exports={
config: path.resolve('src/sequelize/config','config.js'),
'migrations-path': path.resolve('src/sequelize/migrations'),
'seeders-path': path.resolve('src/sequelize/seeders'),
'models-path': path.resolve('src/sequelize/models')
}
and 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
}
},
...
}
来源:https://stackoverflow.com/questions/62826152/sequelize-migration-doesnot-read-dotenv-variable-if-i-dont-run-it-from-root-dir