Dialect needs to be explicitly supplied as of v4.0.0

shumana chowdhury picture shumana chowdhury · Oct 11, 2017 · Viewed 52.4k times · Source

I have been working on a NodeJS project which uses PostgreSQL database. I am trying to implement migration to the database. Also, using Sequelize. After setting up the migration folder and config, it throws error while running db:migrate

The error is: "Dialect needs to be explicitly supplied as of v4.0.0"

Answer

JPero picture JPero · Jan 8, 2018

Solution for me was based on what I had set for my NODE_ENV variable.

echo $NODE_ENV

If you do not have anything set for that variable, try setting it with the following:

export NODE_ENV=development

If a value is present, make sure you have an entry in your config file for that value. For me, I like to use local. So I had to update my config to this:

{
 local: {
  username: 'root',
  password: null,
  database: 'database_dev',
  host: '127.0.0.1',
  dialect: 'postgres'
  },
 development: {
  username: 'root',
  password: null,
  database: 'database_dev',
  host: '127.0.0.1',
  dialect: 'postgres'
  },
  test: {
  username: 'root',
  password: null,
  database: 'database_test',
  host: '127.0.0.1',
  dialect: 'postgres'
 },
 production: {
  username: 'root',
  password: null,
  database: 'database',
  host: '127.0.0.1',
  dialect: 'postgres'
 }
}