node.js - Sequelize bulk synchronization does nothing -


i'm unable sequelize.sync() work. calling sync() on each model definition works flawlessly calling sequelize instance appears nothing, if model manager had no registered models in it.

consider following:

function syncall() {     console.log('retrieving exported models...')     let models = require('./models')     for(var modelname in models) {         let model = models[modelname]         // define() wraps regular sequelize.define() call         // model.define().sync() works!         model.define()     }      console.log('all exported models have been defined! syncing database...')     sequelize.sync({         logging: true     }).then(function() {         // operation completes no command executed in db         console.log('database synchronization complete!')     }).catch(function(error) {         console.log("database synchronization error:\n\t${error}")     }) } 

just trying understand i'm missing, why bulk synchronization isn't working me?

afaik need models defined before calling sequelize.sync(), right?!

edit 1

some info environment: i'm using node 5.6 under debian postgres

edit 2

found problem. refer end of accepted answer...

this code sequelize example works fine me:

var sequelize = new sequelize(config.database, config.username, config.password, config); var db: = {};  var task = sequelize.define("task", {   title: sequelize.string }, {   classmethods: {     associate: function(models) {       task.belongsto(models.user, {         ondelete: "cascade",         foreignkey: {           allownull: false         }       });     }   } });  var user = sequelize.define("user", {   username: sequelize.string }, {   classmethods: {     associate: function(models) {       user.hasmany(models.task);     }   } });  db.user = user; db.task = task;  object.keys(db).foreach(function(modelname) {   if ("associate" in db[modelname]) {     db[modelname].associate(db);   } });  sequelize.sync().then(() => {   // code here }); 

models have been defined via "sequelize.define(...)" , after "sequelize.sync()" has been called.

update 1

i'm using sqlite:

var config: = {     "dialect": "sqlite",     "storage": "./db.development.sqlite" }; 

update op

i've spotted diference between code , mine. due bug in logic sequelize.define() , sequelize.sync() being called different sequelize instances (i.e different connections) , each connection has own modelmanager there no models sync in second connection object.


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -