TypeError: models[model].defineConstraints is not a function

85
July 26, 2022, at 8:00 PM

I`m trying to undestand whats going on and why defineConstraints is not a function. can someone help me ?

Heres examples of my code.

index.js

const Sequelize = require('sequelize');
  config = require('config');
const dbConf = config.get('database');
console.log(dbConf);

const sequelize = new Sequelize(dbConf.database, dbConf.user, dbConf.password,{
  dialect: 'postgres',
  host: dbConf.host,
  port: dbConf.port,
  logging: console.log
});
sequelize.Model = Sequelize.Model;
const models = {
  User: sequelize.import(__dirname + '/models/user.js'),
  Service: sequelize.import (__dirname + '/models/service.js'),
  Subscriber: sequelize.import (__dirname + '/models/subscriber.js'),  
};
for(const model in models) {
  models[model].defineConstraints(models);
}
models.Op = Sequelize.Op;
models.sequelize = sequelize;
module.exports = models;
Rent Charter Buses Company
READ ALSO
use nodejs var as json object statement?

use nodejs var as json object statement?

how do I use a nodejs var inside a json statement, I dont realy have the required vocabulary to explain but here is my simplifyed code:

98
Store files on mongodb database or server

Store files on mongodb database or server

I have a website built on MongoDB which has files to be downloaded by users other than images ( it can be a software installer orexe file

72
Best practices to handle Cart

Best practices to handle Cart

I am trying to create a E-commerce project using MERN stack and was wonderingHow to go about creating a cart for a user

102