javascript - Node.js Sequelize ORM model issue -
i using sequelize node.js orm web application. facing following issue when start node server.
following further details
error:
project_directory_path\node_modules\sequelize\lib\sequelize.js:322
model.init(attributes, options);
typeerror: model.init not function @ sequelize.define (project_directory_path\node_modules\sequelize\lib\sequelize.js:322:11) @ module.exports (project_directory_path\models\sequelize\app_config_setting.js:2:41) @ sequelize.import (project_directory_path\node_modules\sequelize\lib\sequelize.js:379:32) @ project_directory_path\models\index.js:34:48 @ array.foreach (native) @ object. (project_directory_path\models\index.js:31:6) @ module._compile (module.js:425:26) @ object.module._extensions..js (module.js:432:10) @ module.load (module.js:356:32) @ function.module._load (module.js:311:12) @ module.require (module.js:366:17) @ require (module.js:385:17) @ object. (project_directory_path\server.js:12:14) @ module._compile (module.js:425:26) @ object.module._extensions..js (module.js:432:10) @ module.load (module.js:356:32) @ function.module._load (module.js:311:12) @ function.module.runmain (module.js:457:10) @ startup (node.js:136:18) @ node.js:972:3
version:
node version v5.0.0, sequelize version: "^4.4.2", dialect: "mysql"
index.js file (to load models)
var fs = require('fs'); var path = require('path'); var sequelize = require('sequelize'); var sequelizeconnection = require('../configs/dbconnection.js').exposesequelizeconnectionobj(); var sequelizemodeldir = path.join(__dirname, 'sequelize'); var dbmodels = {}; fs.readdirsync(sequelizemodeldir) //avoiding index.js , other files //expect model files .filter(function (file) { return (file.indexof(".") !== 0) && (file !== "index.js"); }) //iterating on each models , importing //in sequelize connection object .foreach(function (file) { var dir = 'sequelize/'; var models = sequelizeconnection.import(path.join(sequelizemodeldir, file)); dbmodels[models.name] = models; }); //exposing models module.exports = dbmodels; dbmodels.sequelize = sequelizeconnection;
one of model (just idea)
module.exports = function (sequelize,datatypes) { var roles = sequelize.define( 'roles', { id: {autoincrement: true, type: datatypes.integer(11), allownull: false, primarykey: true}, role_name: {type: datatypes.enum('super_admin'), allownull: false}, code_name: {type: datatypes.enum('super_admin'), allownull: false}, row_status: {type: datatypes.enum('active','inactive'), allownull: true} }, { timestamps: false, paranoid: true, freezetablename: true, tablename: 'roles' } ); return roles; };
database connection file:
var sequelize = require('sequelize'); var sequelizeconnectionobj = new sequelize(process.env.db_database_name, process.env.db_username, process.env.db_password, { host: process.env.db_hostname, dialect: 'mysql', define: { timestamps: false }, dialectoptions: { multiplestatements: true }, logging: false, pool: { max: 15, min: 0, idle: 10000 } }); exports.exposesequelizeconnectionobj = function connectsequelize() { return sequelizeconnectionobj; };
issue resolved updating node module
i-e npm update
just update node modules.
Comments
Post a Comment