[英]Knex.js Schema: Multicolumn Index
Is there a way to specify a multicolumn index in the Knex.js schema? 有没有办法在Knex.js模式中指定多列索引? Or must one drop to raw and do an alter table
? 或者必须放弃原始并做一个转换alter table
?
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. 您可以直接在表上使用.index chainable,并为索引字段和索引名称传递数组。
knex.schema.createTable(function(table) {
table.bigInteger('_id').unsigned().primary();
table.string('fieldA');
table.string('fieldB');
table.index(['fieldA','fieldB'], 'index_name');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.