续集方言错误

Posted

技术标签:

【中文标题】续集方言错误【英文标题】:Sequelize Dialect Error 【发布时间】:2016-05-17 07:08:26 【问题描述】:

我最近在安装 lodash 后在我的应用程序中遇到了一个奇怪的错误。我不知道它是否对我的设置产生了任何影响,但是突然间,sequelize 会在方言属性中抛出一个错误,即不支持 mysql 并且无法读取 property 'dialectName' of undefined。我不确定为什么会发生这种情况,因为我使用 sequelize 有一段时间了,但从未出现过。

使用节点v0.10.40运行

完全错误:

/sequelize/lib/sequelize.js:205
    throw new Error('The dialect ' + this.getDialect() + ' is not supported. S
          ^
Error: The dialect mysql is not supported. Supported dialects: mariadb, mssql, mysql, postgres, and sqlite. (TypeError: Cannot read property 'dialectName' of undefined)
    at new Sequelize (/Users/user/Desktop/Projects/node/app-test/node_modules/sequelize/lib/sequelize.js:205:11)
    at Object.<anonymous> (/Users/user/Desktop/Projects/node/app-test/app/models/db-index.js:4:17)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/user/Desktop/Projects/node/app-test/config/passport.js:3:14)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/user/Desktop/Projects/node/app-test/app/controllers/site-routes.js:4:16)

我的方言设置在哪里:

db-index.js:

var Sequelize = require('sequelize');
var path = require('path');
var config = require(path.resolve(__dirname, '..', '..','./config/config.js'));
var sequelize = new Sequelize(config.database, config.username, config.password, 
    host:'localhost',
    port:'3306',
    dialect: 'mysql'
);

sequelize.authenticate().then(function(err) 
    if (!!err) 
        console.log('Unable to connect to the database:', err)
     else 
        console.log('Connection has been established successfully.')
    
);

var db = 

db.Member = sequelize.import(__dirname + "/member");

db.Organization = sequelize.import(__dirname + "/organization");

db.User = sequelize.import(__dirname + "/user");

db.DiscoverySource = sequelize.import(__dirname + "/discovery-source");

db.User.associate(db);
db.Organization.associate(db);
db.DiscoverySource.associate(db);

db.sequelize = sequelize;
db.Sequelize = Sequelize;

sequelize.sync();

module.exports = db;

package.json:


  "name": "app-test",
  "version": "1.0.0",
  "description": "",
  "engines": 
    "node": "5.0.0"
  ,
  "main": "app.js",
  "scripts": 
    "test": "echo \"Error: no test specified\" && exit 1"
  ,
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": 
    "bcrypt-nodejs": "0.0.3",
    "body-parser": "^1.14.1",
    "cheerio": "^0.20.0",
    "connect-flash": "^0.1.1",
    "cookie-parser": "^1.4.0",
    "express": "^4.13.3",
    "express-hbs": "^0.8.4",
    "jquery": "^2.2.0",
    "lodash": "^4.2.1",
    "moment": "^2.10.6",
    "morgan": "^1.6.1",
    "mysql": "^2.9.0",
    "nodemon": "^1.8.1",
    "passport": "^0.3.2",
    "passport-local": "^1.0.0",
    "sequelize": "^3.14.1",
    "session": "^0.1.0"
  

【问题讨论】:

【参考方案1】:

你必须安装包mysql:

npm install mysql --save

祝你好运^^

【讨论】:

@RickJames 你能帮忙吗?

以上是关于续集方言错误的主要内容,如果未能解决你的问题,请参考以下文章

sequelize抛出错误方言需要在express js中显式定义

MSSQL 2014 的错误休眠方言

学习hibernate出现错误--之二(方言)

MySQL8 的休眠方言

无法确定“oracle”的方言

Grails 突然抛出错误无法确定数据库名称的 Hibernate 方言