#5799·knex

NodeJS OOM when attempting add an index using knex.table instead of knex.schema.alterTable

Author: jballentine-sharpenCreated Feb 8, 2024Updated Sep 22, 2026
LabelsNG_bugNG_documentation

Environment

Knex version: 2.4.0 Database + version: mysql 8 OS: macos

Bug

I wrote a migration yesterday and couldn't figure out why I was getting a nodeJS OOM error until I realized I was using knex.table instead of knex.schema.alterTable. My migration was just adding an index to an existing table, and I'm not sure what knex.table was trying to do considering the correct form would be either knex.schema.table or knex.schema.alterTable

The reason I made this mistake is because the example for adding an index uses knex.table in this way: https://knexjs.org/guide/schema-builder.html#index

the json documentation is the only other place that uses knex.table: https://knexjs.org/guide/schema-builder.html#json

I'm assuming these are just typos and are meant to be knex.schema.table or knex.schema.createTable.

Either way, the OOM is definitely an issue, and an appropriate error message being thrown would be nice. Or, just a correction to the documentation.

Error message:

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

I'm assuming something like this will recreate it:

migration 1:

javascript
await knex.schema.createTable('test', (table) => {
    table.increments('id').primary();
    table.string('whatever').notNullable();
    table.string('other').notNullable();
    table.string('testing').notNullable();
  });

migration 2:

javascript
await knex.table('test', table => table.index(['whatever', 'other'], 'idx-test'));