The error I'm getting is this:
C:\Users\brend\project\server\node_modules\sequelize\lib\sequelize.js:392
this.importCache[path] = defineCall(this, DataTypes);
^
TypeError: defineCall is not a function
at Sequelize.import (C:\Users\brend\project\server\node_modules\sequelize\lib\sequelize.js:392:32)
at fs.readdirSync.filter.forEach (C:\Users\brend\project\server\src\models\index.js:20:35)
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 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
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
There's also the thing that in my app.js sequelize.sync()
is not defined, at least that's what my IDE indicates.
I found this on github sequelize github, replace
const model = sequelize.import(path.join(__dirname, file));
with
var model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes);
It works for me with sequelize 6.3.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With