Sequelize migration doesnot read dotenv variable if I don't run it from root directory. why?

本小妞迷上赌 提交于 2020-07-23 06:21:21

问题


This is what I did

  1. require('dotenv').config() in the config file
  2. set .sequelizerc in the root directory like below
  3. set .sequelie file to point config, migrations, models, seeds directory from root directory
  4. ran npx seuqlie-cli db:migrate form root directory. It work!
  5. ran npx seuqlie-cli db:migrate form sequelize directory. It doesn't read dotenv variable and come with connect 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!