question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

knex migrate:latest hangs

See original GitHub issue

Here is my knexfile.js

module.exports = {
  development: {
    client: 'pg',
    connection: {
      "host": "my_host",
      "database": "my_db",
      "user": "my_db_user",
      "password": "my_db_password"
    }
  }
};

and my migrations

user

'use strict';

exports.up = function(knex, Promise) {
    return knex.schema.createTable('users', function (table) {
        table.increments('id').primary();
        table.integer('profile_id').references('profiles.id');
        table.dateTime('created_at');
        table.dateTime('updated_at');
        table.string('user_name');
        table.string('password');
        table.integer('is_enabled');
        table.uuid('token');
    });
};

exports.down = function(knex, Promise) {
    return knex.schema.dropTable('users');
};

profile

'use strict';

exports.up = function(knex, Promise) {
    return knex.schema.createTable('profiles', function (table) {
        table.increments('id').primary();
        table.integer('user_id').references('users.id');
        table.dateTime('created_at');
        table.dateTime('updated_at');
        table.string('name');
        table.string('email');
        table.string('photo');
        table.string('location');
        table.string('website');
        table.text('bio');
    });
};

exports.down = function(knex, Promise) {
    return knex.schema.dropTable('profiles');
};

role

'use strict';

exports.up = function(knex, Promise) {
    return knex.schema.createTable('roles', function (table) {
        table.increments('id').primary();
        table.dateTime('created_at');
        table.dateTime('updated_at');
        table.string('name');
    });
};

exports.down = function(knex, Promise) {
    return knex.schema.dropTable('roles');
};

roles_users

'use strict';

exports.up = function(knex, Promise) {
    return knex.createTable('roles_users', function (table) {
        table.integer('role_id').references('roles.id');
        table.integer('user_id').references('users.id');
    });
};

exports.down = function(knex, Promise) {
    return knex.schema.dropTable('roles_users');
};

When I run: knex migrate:latest it just hangs, no error, no output whatsoever, even with --debug. I’ve traced it down to this line:

https://github.com/tgriesser/knex/blob/master/lib/migrate/index.js#L120

The call to hasTable does return 0:

https://github.com/tgriesser/knex/blob/master/lib/dialects/postgres/schema/schema.js#L35

But I would have thought it would have resolved 0 there, but it does not. Any ideas?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
socketwizcommented, Dec 29, 2014

Now that I have some output I was able to fix my migrations and everything is working well now:

C:\myapp>knex migrate:latest Batch 1 run: 3 migrations C:myapp\migrations\20141228092057_users.js C:\myapp\migrations\20141228093118_roles.js C:\myapp\migrations\20141228095024_roles_users.js

C:\myapp>knex migrate:rollback Batch 1 rolled back: 3 migrations C:\myapp\migrations\20141228095024_roles_users.js C:\myapp\migrations\20141228093118_roles.js C:\myapp\migrations\20141228092057_users.js

Not sure what I had all jacked up, but working well now.

0reactions
jmrossycommented, Jun 15, 2020

I still see this issue when I run migrations. Tested with knex 0.21.1, pg 8.2.1, running the migrations via JS code (not the CLI)

Read more comments on GitHub >

github_iconTop Results From Across the Web

knex migrate:latest hangs · Issue #608 - GitHub
When I run: knex migrate:latest it just hangs, no error, no output whatsoever, even with --debug. I've traced it down to this line:....
Read more >
javascript - Knex Migrations cause gulp process to hang - Stack ...
Documentation on knex's connection pooling and the explicit destroy command are here. The gulp task becomes this: gulp.task('migrate:latest', function () ...
Read more >
Migrations | Knex.js
Creating new migration files can be achieved by running: ... Please note that if your process unfortunately crashes, the lock will have to...
Read more >
Database Migrations with Knex - Perk
Step 1: Create a new migration file with knex cli ... You can refer back to the Creating a migration file section of...
Read more >
tgriesser/knex - Gitter
@elhigu Ok, but when i use: knex.migrate.latest({ migrationSource: new WebpackMigrationSource(require.context('./migrations', false, /.ts$/)) }).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found