gpt4 book ai didi

sequelize.js - 类型错误 : defineCall is not a function at Sequelize. 导入

转载 作者:行者123 更新时间:2023-12-03 22:22:16 24 4
gpt4 key购买 nike

将我的 User.js 模型定义为如下但低于异常

错误

PS C:\Users\meghshyam\Documents\express_node_mysql_handlebars> node server.js C:\Users\meghshyam\Documents\express_node_mysql_handlebars\node_modules\sequelize\lib\sequelize.js:691 this.importCache[path] = defineCall(this, DataTypes); ^

TypeError: defineCall is not a function at Sequelize.import (C:\Users\meghshyam\Documents\express_node_mysql_handlebars\node_modules\sequelize\lib\sequelize.js:691:30) at C:\Users\meghshyam\Documents\express_node_mysql_handlebars\models\index.js:23:36 at Array.forEach (native) at Object. (C:\Users\meghshyam\Documents\express_node_mysql_handlebars\models\index.js:22: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) at Object. (C:\Users\meghshyam\Documents\express_node_mysql_handlebars\server.js:16:10) 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 Function.Module.runMain (module.js:441:10)


 "use strict";

module.exports = function(sequelize, DataTypes) {
var User = sequelize.define("User",
{
//timestamps: true,
// id:DataTypes.INTEGER,
username:{
type:DataTypes.STRING,
validate:{
isEmail:true
}
},
password: {
type: DataTypes.STRING,
validate:{
len:[6,12],
notNull:true,
notEmpty:true
}
},
role:{
type: DataTypes.INTEGER,
validate:{
notNull:true,
notEmpty:true,
isNumeric:true
},
}
},

{
classMethods: {
associate: function(models) {
// Associating Author with Posts
// When an Author is deleted, also delete any associated Posts
// User.belongsTo(models.Student, {
// onDelete: "cascade"
// });
//user has one teacher record
// User.belongsTo(models.Teacher, {
// onDelete: "cascade"
});
}
}
}
);
return User;
};

最佳答案

这通常是由于在 index.js 中导入了不是 Sequelize 模型的文件引起的。您的模型目录中是否有任何不是模型的内容?在我的情况下,这是因为它正在拉入我的测试文件以及位于同一目录中的模型。尝试在 index.js 中添加另一个检查,它会在其中构建文件列表以排除以 .test.js 结尾的任何内容(或任何等价物)。

关于sequelize.js - 类型错误 : defineCall is not a function at Sequelize. 导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43797572/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com