javascript - How to do knex.js migrations? -


i'm still not sure how migrations knex. here have far. works on up, down gives me fk constraint error though foreign_key_checks = 0.

exports.up = function(knex, promise) {   return promise.all([     knex.raw('set foreign_key_checks = 0;'),      /* create member table */     knex.schema.createtable('member', function (table) {       table.bigincrements('id').primary().unsigned();       table.string('email',50);       table.string('password');        /* create fks */       table.biginteger('referralid').unsigned().index();       table.biginteger('addressid').unsigned().index().intable('address').references('id');     }),      /* create address table */     knex.schema.createtable('address', function (table) {       table.bigincrements('id').primary().unsigned();       table.index(['city','state','zip']);        table.string('city',50).notnullable();       table.string('state',2).notnullable();       table.integer('zip',5).unsigned().notnullable();     }),      knex.raw('set foreign_key_checks = 1;')   ]); };  exports.down = function(knex, promise) {   return promise.all([     knex.raw('set foreign_key_checks = 0;'),      knex.schema.droptable('address'),      knex.schema.droptable('member'),      knex.raw('set foreign_key_checks = 1;')    ]); }; 

figured out wasn't working because of connection pooling. use different connection run each migration task caused foreign key checks not set properly. setting

pool:{   max:1 } 

in migration config file fixed this.


Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -