[英]defineCall is not a function, sequelize error
我一直在尝试找出如何解决由我的index.js文件生成的以下错误。 我正在使用Node,Express和sequelize。
/app/node_modules/sequelize/lib/sequelize.js:691
server_1 | this.importCache[path] = defineCall(this, DataTypes);
server_1 | ^
server_1 |
server_1 | TypeError: defineCall is not a function
据我所知,该错误是由于我将不是sequelize模型的内容导入到index.js文件(请参阅下面的index.js代码)而产生的。 但是我根本找不到问题所在。 下面是代码。 任何帮助将非常感激!
预订型号代码:
var Sequelize = require('sequelize');
var config = require('../config');
var db = require('../services/database');
// 1: The model schema.
var modelDefinition = {
name: {
type: Sequelize.STRING
}
};
// 2: Define the User model.
var BookingModel = db.define('booking', modelDefinition);
// DB relations
BookingModel.associate = (models) => {
BookingModel.hasMany(models.BookingModel, {});
};
module.exports = BookingModel;
Index.js文件的重要部分:
fs
.readdirSync(__dirname)
.filter(function(file) {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
})
.forEach(function(file) {
var model = sequelize.import(path.join(__dirname, file));
db[model.name] = model;
});
序列化模型文件必须采用以下格式,
module.exports = function(connection, Sequelize){
var table = connection.define('table', {
id : Sequelize.INTEGER,
});
return table;
}
在指定的模型中,它会导出模型定义,这就是错误的原因。 sequelize期望每个模型都导出一个返回表定义的函数。
就我而言,这是因为我的index.js
提取了我的测试文件和模型,这些文件和模型位于同一目录中。 确保您的模型目录中没有其他内容,或者如果没有其他文件(例如测试),请确保index.js
在构建文件列表时将它们排除在外。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.