Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequelize 'Dialect needs to be explicitly supplied as of v4.0.0'

I need to run third party application in node.js environment but Sequelize throws 'Dialect needs to be explicitly supplied as of v4.0.0' I've found similar topic here Dialect needs to be explicitly supplied as of v4.0.0 but 'export NODE_ENV=development' doesn't work and I can not find Sequelize config file. How can I fix this error?

Here is code:

const Sequelize = require('sequelize');

const scheme = require('./scheme');

const Op = Sequelize.Op;

const sequelize = new Sequelize(null, null, {

dialect: 'sqlite',
storage: 'db.sqlite3',

operatorsAliases: { $and: Op.and },

logging: false
});

scheme(sequelize);
sequelize.sync();

module.exports.sequelize = sequelize;
module.exports.models = sequelize.models;
like image 643
Mark Polovtsev Avatar asked Jan 23 '18 08:01

Mark Polovtsev


People also ask

What is dialect in Sequelize?

Sequelize is independent from specific dialects. This means that you'll have to install the respective connector library to your project yourself.

Is Sequelize a programming language?

Sequelize is a promise-based ORM for Node. js. It works with PostgreSQL, MySQL, SQLite and MSSQL dialects and features solid transaction support, relations, read replication and more. Object Relational Mapping (ORM) is a technique of accessing a relational database from an object-oriented language.


2 Answers

You simply supply the dialect when you initialize sequelize;

const sequelize = new Sequelize('database', 'username', 'password', {
  host: 'localhost',
  dialect: // pick one of 'mysql','sqlite','postgres','mssql',
});
like image 106
Michael McCabe Avatar answered Sep 21 '22 15:09

Michael McCabe


Node cannot find your environment to load in the config file.

You can easily fix by running this

 export NODE_ENV=development; npx sequelize db:migrate

This should export to NODE_ENV the environment needed to run it.

like image 35
Jason Avatar answered Sep 20 '22 15:09

Jason