Hello to all! New to backend/database, and I'm trying to learn how to use the Sequelize ORM. I'm trying to connect everything and it's giving me a TypeError: db.define is not a function error. My code is belowdb.jsconst Sequelize = require('sequelize') const sequelize = new Sequelize(process.env.DB_NAME, process.env.DB_USER, process.env.DB_USER_PASSWORD, { host:'localhost', dialect:'mysql', define:{ timestamps:false }, pool:{ max:5, min:0, acquire:30000, idle:10000 } })var db = {};db.Sequelize = Sequelize; db.sequelize = sequelize;db.customers = require('../models/Customer.js')(sequelize, Sequelize); db.booths = require('../models/Booth')(sequelize, Sequelize);db.customers.belongsTo(db.booths); db.booths.hasMany(db.customers);module.exports = db; Customer.js Modelconst Sequelize = require('sequelize') const db = require('../config/database')const Customer = db.define('Customers', { customer_id:{ type:Sequelize.INTEGER, primaryKey:true, autoIncrement:true }, customer_name:{ type:Sequelize.STRING }, customer_phone:{ type:Sequelize.STRING }, active:{ type:Sequelize.BOOLEAN } })module.exports = CustomerBooth Model is pretty much the same. Any Ideas?
Submitted November 26, 2019 at 08:13PM by kingducasse
No comments:
Post a Comment