Sunday, 9 April 2017

Knex migration not working

I am new to knex migrations and for the past 2 days I have been struggling to get it working but nothing happen. I am trying to run my migrations programmatically using the knex.migration object.

First using the cli, I create a migration file in the migrations directory. Here is its content:

exports.up = function(knex, Promise) {
   return Promise.all([
        knex.schema.createTable('users', function (table) {
            table.increments('id').primary();
            table.string('username');
            table.string('password');
            table.string('email');
            table.string('name');
            table.timestamp('date');
        }),
    ]);
};

exports.down = function(knex, Promise) {

};

Then from my code I initialize the Knex object:

var knex = Knex({
        client:'sqlite3',
        connection:{
            filename: root('bin/knex.sqlite')
        }
    });

Then I execute the migration:

knex.migrate.latest().then(()=>{
        // console.log()
    }).catch(err =>{
        // 
    });

But absolutely nothing happens. My migration file is never executed and there is no error or warning message. So I don't know where to look at to start searching for the problem. When I look at my sqlite database, I can see that tables knex_migrations, knex_migrations_lock and sqlite_sequence have been created.

So what I am doing wrong here? Is there something I am missing? Thanks for any suggestion



via TheSoul

No comments:

Post a Comment