Trung Tran
Trung Tran

Reputation: 13771

knexjs postgresql migration not running properly

I am building an app use node + express + postgresql + knexjs ORM. I'm trying to run a migration:

knex migrate:latest

But my console keeps returning:

Using environment: development

Already up to date

And this results in my tables not being created.. Here's my migration file:

exports.up = function(knex, Promise) {

    return Promise.all([

            knex.schema.createTable('address', function(table) {

                table.increments();
                table.string('address_id');
                table.string('addr_1');
                table.string('addr_2');
                table.string('city');
                table.string('state');
                table.string('zip');

        ]);
};


exports.down = function(knex, Promise) {

    return Promise.all([

            knex.schema.dropTable(host_domain + '.address'),

        ]);

};

Does anyone know what might be going on?

Note - the tables have NOT been created at the moment I run knex migrate:latest.

Thanks in advance!

Upvotes: 1

Views: 1349

Answers (1)

John Syomochkin
John Syomochkin

Reputation: 51

Knex implement migrations in environment = development by default. You need run knex migrations by your environment.

For example, you have next knexfile.js:

module.exports = {
    myenv: { // it is name of environment
       client: 'pg',
       connection: {
           user: 'me',
           database: 'my_app'
       }
     }
};

Command in console:

knex migrate:latest --env myenv

Upvotes: 1

Related Questions