sequelize.import 上的错误:defineCall 不是函数 [英] Error on sequelize.import: defineCall is not a function
本文介绍了sequelize.import 上的错误:defineCall 不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到的错误是:
C:Usersrendprojectserver
ode_modulessequelizelibsequelize.js:392
this.importCache[path] = defineCall(this, DataTypes);
^
TypeError: defineCall is not a function
at Sequelize.import (C:Usersrendprojectserver
ode_modulessequelizelibsequelize.js:392:32)
at fs.readdirSync.filter.forEach (C:Usersrendprojectserversrcmodelsindex.js:20:35)
我正在学习使用 node、vue 和一堆库,但我无法弄清楚这一点.
I'm learning as I go with node, vue and a bunch of libraries, and I haven't been able to figure this out.
index.js 如下:
index.js is as following:
const fs = require('fs')
const path = require('path')
const Sequelize = require('sequelize')
const config = require('../config/config')
const db = {}
const sequelize = new Sequelize(
config.db.database,
config.db.user,
config.db.password,
config.db.options
)
fs
.readdirSync(__dirname)
.filter((file) =>
file !== 'index.js'
)
.forEach((file) => {
const model = sequelize.import(path.join(__dirname), file)
db[model.name] = model
})
db.sequelize = sequelize
db.Sequelize = Sequelize
module.exports = db
这是我的 User.js,这是我目前唯一的模型:
And here is my User.js, which is the only model I have currently:
module.exports = (sequelize, DataTypes) =>
sequelize.define('User', {
email: {
type: DataTypes.STRING,
unique: true
},
password: DataTypes.STRING
})
如果需要,我的文件夹结构:
And if necessary, my folder structure:
-src
--app.js
--routes.js
--config
----config.js
--controllers
----AuthenticationController.js
--models
----index.js
----User.js
还有一点,在我的 app.js 中 sequelize.sync()
没有定义,至少我的 IDE 是这样表示的.
There's also the thing that in my app.js sequelize.sync()
is not defined, at least that's what my IDE indicates.
推荐答案
我在github上找到了这个sequelizegithub,替换
I found this on github sequelize github, replace
const model = sequelize.import(path.join(__dirname, file));
与
var model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes);
它适用于我的续集 6.3.0
It works for me with sequelize 6.3.0
这篇关于sequelize.import 上的错误:defineCall 不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文