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

标签 node.js error-handling sequelize.js

我需要在 node.js 环境中运行第三方应用程序,但 Sequelize 抛出“从 v4.0.0 开始需要显式提供方言” 我在这里找到了类似的主题 Dialect needs to be explicitly supplied as of v4.0.0但是 'export NODE_ENV=development' 不起作用,我找不到 Sequelize 配置文件。 我该如何解决这个错误?

代码如下:

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;

最佳答案

您只需在初始化 sequelize 时提供方言;

const sequelize = new Sequelize('database', 'username', 'password', {
  host: 'localhost',
  dialect: // pick one of 'mysql','sqlite','postgres','mssql',
});

关于node.js - Sequelize 'Dialect needs to be explicitly supplied as of v4.0.0',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48397401/

相关文章:

node.js - Typeorm连接到多个数据库

excel - vbObjectError 应该使用哪些数字?

error-handling - 在 Golang 中运行 exec.Command 时如何调试 "exit status 1"错误

node.js - 如何解决promise.all()并想要删除一个级别的对象

node.js - 如何将主代码与index.js Electron 分开?

javascript - 在 res.redirect 上传递变量

exception - 何时对域类中的异常使用断言

mysql - Sequelize - 在where条件下关联表列值

javascript - 可以 Sequelize sum、count、group by 还是我应该使用 sequelize.query 选项?

node.js - 如何将 Webpack 与 ReactJS 和 NodeJS 一起使用?