android房间迁移指数的变化

时间:2018-02-18 16:00:27

标签: android migration android-room

旧实体如下:

@Entity(tableName = "d_course",
    foreignKeys = @ForeignKey(entity = DUser.class, parentColumns = "id", childColumns = "studio"),
    indices = @Index(value = "studio"))

新实体如下:

@Entity(tableName = "d_course",
    foreignKeys = @ForeignKey(entity = DUser.class, parentColumns = "id", childColumns = "studio"),
    indices = @Index(value = {"id", "studio"}))

如何迁移此指数更改。

1 个答案:

答案 0 :(得分:3)

尝试在迁移中指定此索引更改,例如(Kotlin):

val MIGRATION_1_2 = object : Migration(1, 2) {
    override fun migrate(database : SupportSQLiteDatabase) {
        ...
        database.execSQL("CREATE INDEX index_d_course_id_studio ON  d_course(id, studio)")
    }
}