21

Is there a way to specify a multicolumn index in the Knex.js schema? Or must one drop to raw and do an alter table?

Daniel
  • 38,041
  • 11
  • 92
  • 73

1 Answers1

34

Figured this out. You can use the .index chainable on the table directly and pass an array for the index fields and a name for the index.

knex.schema.createTable(function(table) {
  table.bigInteger('_id').unsigned().primary();
  table.string('fieldA');
  table.string('fieldB');
  table.index(['fieldA','fieldB'], 'index_name');
});
Daniel
  • 38,041
  • 11
  • 92
  • 73