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
?
Asked
Active
Viewed 1.6k times
1 Answers
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
-
9that documentation :( – light24bulbs Nov 19 '14 at 20:23
-
seems that composite index's comment will lead a mysql error. – Sinux Mar 04 '16 at 12:54