oderfla
oderfla

Reputation: 1797

sequelize cli not using postgres

Running

sequelize db:migrate

prints out:

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

Then having a look at config/development.json I see:

{
    "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"
    }
}

Why? Why is sequelize still trying to go to mysql port? ialso added the port as you can see in the config file. I could not find any resource saying postgres is not supported. But it seems sequelize-cli still doesn't care about the dialect or even the port number I entered in config-file.

Upvotes: 1

Views: 925

Answers (1)

piotrbienias
piotrbienias

Reputation: 7401

It seems like your NODE_ENV is different than development, test or production, because if it would match any of them, you would obtain a message like

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

However, in your case it does not print which environment it uses, so it means it is none from your development.json file. You can try it with

sequelize db:migrate --env development

According to sequelize-cli source code, it gets the env variable with use of getEnvironment method which is like that:

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

If you do not pass the --env argument, then it takes current NODE_ENV. It would mean that yours is different.

Upvotes: 3

Related Questions