顺序配置读取错误的方言

时间:2018-11-16 11:59:33

标签: sequelize.js sequelize-cli

我正在更新我的sequezlie配置文件,以便在运行cli migration命令时可以运行env变量。对于启用了存储的env变量的远程服务器,我的设置工作正常,但是除非运行dotenv,否则我的本地环境(像所有其他环境一样)不会起作用。仅在识别的环境为dotenv并且控制台日志输出正确的development的{​​{1}}的情况下,才在配置文件中配置process.env.DB_DIALECT,但是由于某些原因,在迁移期间,sequelize告诉我下载postgres。谁能帮助解决这个奇怪的问题?

这是我的终端输出和错误消息的开头:

mysql

这是我的配置文件:

DEVELOPMENT DOTENV
postgres
Loaded configuration file "config/config.js".
Error: Please install mysql package manually
    at new ConnectionManager (/Users/user/Desktop/Projects/node/app/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:23:11)
    at new MysqlDialect (/Users/user/Desktop/Projects/node/app/node_modules/sequelize/lib/dialects/mysql/index.js:12:28)
    at new Sequelize (/Users/user/Desktop/Projects/node/app/node_modules/sequelize/lib/sequelize.js:220:18)

这是我的迁移文件:

var express = require('express');
var app = express();
var path = require('path');

if(app.get('env') === 'development'){
    console.log('DEVELOPMENT DOTENV')
    require('dotenv').config();

};
console.log(process.env.DB_DIALECT) //postgres

module.exports = {
    "development": {
        "username": process.env.DB_LOCAL_USERNAME,
        "password": process.env.DB_LOCAL_PASSWORD,
        "database": process.env.DB_LOCAL_DATABASE,
        "host": "127.0.0.1",
        "dialect": process.env.DB_DIALECT,
        "migrationStorageTableName": "sequelize_meta",
        "autoMigrateOldSchema": true
    },
    "staging": {
        "username": process.env.RDS_USERNAME,
        "password": process.env.RDS_PASSWORD,
        "database": process.env.RDS_DATABASE,
        "host": process.env.RDS_HOSTNAME,
        "dialect": process.env.DB_DIALECT,
        "migrationStorageTableName": "sequelize_meta"
    },
    "production": {
        "username": process.env.RDS_USERNAME,
        "password": process.env.RDS_PASSWORD,
        "database": process.env.RDS_DATABASE,
        "host": process.env.RDS_HOSTNAME,
        "dialect": process.env.DB_DIALECT,
        "migrationStorageTableName": "sequelize_meta"
    }
}

0 个答案:

没有答案