sequelize cli 不使用 postgres

sequelize cli not using postgres

运行

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 端口?我还添加了您在配置文件中看到的端口。我找不到任何资源说不支持 postgres。但似乎 sequelize-cli 仍然不关心方言,甚至不关心我在配置文件中输入的端口号。

您的 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 文件的 none。你可以试试

sequelize db:migrate --env development

根据sequelize-cli源代码,它使用getEnvironment方法获取env变量是这样的:

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

如果您不传递 --env 参数,则它采用当前 NODE_ENV。这意味着你的不一样。