在Sequelize迁移中定义部分索引?
我现在在我的模型定义中使用以下索引:
{ name: 'unique_partner_id', unique: true, fields: ['partnerId'], where: { email: { $ne: null } } }
但是,我想使用迁移而不是同步,所以我试图将此定义从模型移动到初始迁移文件。
有一个queryInterface.addIndex()
方法,但是,我找不到任何文档。
那么,如何使用queryInterface
定义一个部分索引呢?
我正在寻找如何在模型中做到这一点,你的问题回答了我的。 所以现在我要为你回答这个问题! 这是最适合我的function:
up: function(queryInterface, Sequelize) { return queryInterface.addIndex( 'tablename', ['column1', 'column2'], { name: 'indexname', where: {column3: true} } ); }