This is my first stab at using Sequelize and I am trying get a tutorial to work.
I initially used mysql but I got an error to update to mysql2 which I did.
I get the error below.
Can anyone see what I am doing wrong?
Error:
node_modules/sequelize/lib/sequelize.js:380
this.importCache[path] = defineCall(this, DataTypes);
TypeError: defineCall is not a function
part of package.json
"dependencies": {
"body-parser": "^1.17.2",
"dotenv": "^4.0.0",
"ejs": "^2.5.7",
"express": "^4.15.3",
"express-session": "^1.15.5",
"md5": "^2.2.1",
"multer": "^1.3.0",
"mysql": "^2.14.1",
"mysql2": "^1.4.1",
"node-datetime": "^2.0.0",
"nodemailer": "^4.0.1",
"passport": "^0.4.0",
"passport-local": "^1.0.0",
"password-hash": "^1.2.2",
"random-string": "^0.2.0",
"sequelize": "^4.5.0"
}
app.js
var models = require("./models");
models.sequelize.sync().then(function() {
console.log('Nice! Database looks fine')
}).catch(function(err) {
console.log(err, "Something went wrong with the Database Update!")
});
/models/index.js
"use strict";
var fs = require("fs");
var path = require("path");
var Sequelize = require("sequelize");
var env = process.env.NODE_ENV || "development";
var config = require(path.join(__dirname, '..', 'config', 'config.json'))[env];
var sequelize = new Sequelize(config.database, config.username, config.password, config);
var db = {};
fs
.readdirSync(__dirname)
.filter(function(file) {
return (file.indexOf(".") !== 0) && (file !== "index.js");
})
.forEach(function(file) {
var model = sequelize.import(path.join(__dirname, file));
db[model.name] = model;
});
Object.keys(db).forEach(function(modelName) {
if ("associate" in db[modelName]) {
db[modelName].associate(db);
}
});
db.sequelize = sequelize;
db.Sequelize = Sequelize;
module.exports = db;