1

跑步

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 仍然不关心方言甚至我在配置文件中输入的端口号。

4

1 回答 1

3

看起来您的与,或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方法获取环境变量:

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

如果你不传递--env参数,那么它需要 current NODE_ENV。这将意味着你的不同。

于 2017-03-01T18:13:37.327 回答