Sequelize错误:Index.js中未定义defineCall [英] Sequelize error: defineCall not defined in Index.js
问题描述
我一直在收到这个sequelize错误
I've been receiving this sequelize error
/node_modules/sequelize/lib/sequelize.js:508
this.importCache[path] = defineCall(this, DataTypes);
^
TypeError: defineCall is not a function
at module.exports.Sequelize.import (/node_modules/sequelize/lib/sequelize.js:508:32)
at /models/Index.js:16:33
at Array.forEach (native)
at Object.<anonymous> (/Users/vincentporta/Desktop/RCB_Classwork/cesarcell/models/Index.js:15:4)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
我将其范围缩小到下面的Index.js
文件中的注释代码
I've narrowed it down to the commented code in my Index.js
file below
"use strict";
var fs = require("fs");
var path = require("path");
var Sequelize = require("sequelize");
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;
// });
This commented code below breaks it
//.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;
有人知道为什么会发生此错误吗?
Does anyone know why this error is occuring?
推荐答案
这通常意味着您正在尝试导入非序列化对象.如果索引文件的名称为Index.js
,则需要在过滤器功能中对其进行更改(首字母大写)
This usually means you're trying to import a non-sequelize object. If the name of your index file is Index.js
then you need to change it in your filter function (first letter is capital)
return (file.indexOf(".") !== 0) && (file !== "Index.js");
因为它区分大小写.还要检查导入文件夹中是否没有其他文件没有定义序列化模型.如果只是将它们添加到您的过滤器功能中.
As it is case sensitive. Also check that there aren't any other files in your import folder which don't define sequelize model. If there are just add them to your filter function.
这篇关于Sequelize错误:Index.js中未定义defineCall的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!