【发布时间】:2018-08-16 17:42:43
【问题描述】:
我正在使用 Knex.js。我想用 WHERE 子句为我的表创建一个唯一索引:
db.schema.createTable('newTable', function(t) {
t.increments()
t.string('col1').defaultTo(null)
t.string('col2').notNullable()
t.integer('col3').notNullable()
t.unique(['col1', 'col2', 'col3']).whereNotNull('col1')
t.unique(['col2', 'col3']).whereNull('col1')
})
我尝试为表创建两个部分索引。但是,whereNotNull 不能与 unique 函数链接。如何使用 'where' 子句创建唯一索引?
【问题讨论】:
标签: postgresql knex.js