sequelize cli不使用postgres

时间:2017-03-01 16:37:05

标签: sequelize.js sequelize-cli

运行

sequelize db:migrate

打印出来:

Sequelize [Node: 6.9.4, CLI: 2.4.0, ORM: 3.24.6]

Loaded configuration file "config\development.json".
Unable to connect to database: SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306

然后看看config / development.json,我看到了:

{
    "development": {
    "username": "postgres",
    "password": "password",
    "database": "mydb",
    "host": "127.0.0.1",
    "port": "5432",
    "dialect": "postgres"
    },
    "test": {
    "username": "postgres",
    "password": "password",
    "database": "mydb",
    "host": "127.0.0.1",
    "port": "5432",
    "dialect": "postgres"
    },
    "production": {
    "username": "postgres",
    "password": "password",
    "database": "mydb",
    "host": "127.0.0.1",
    "port": "5432",
    "dialect": "postgres"
    }
}

为什么呢?为什么sequelize仍然试图去mysql端口? ialso添加了端口,如配置文件中所示。我找不到任何资源说不支持postgres。但似乎sequelize-cli仍然不关心我在配置文件中输入的方言甚至端口号。

1 个答案:

答案 0 :(得分:1)

您的NODE_ENV似乎与developmenttestproduction不同,因为如果它与任何一个匹配,您将获得类似

Loaded configuration file "config/development.json".
Using environment "development".
Unable to connect to database: SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306

但是,在您的情况下,它不会打印它使用的环境,因此它表示您的development.json文件中没有。您可以尝试使用

sequelize db:migrate --env development

根据sequelize-cli源代码,它使用getEnvironment方法获取env变量,如下所示:

getEnvironment: function () {
    return args.env || process.env.NODE_ENV || 'development';
}

如果您未传递--env参数,则需要当前NODE_ENV。这意味着你的不同。