旧实体如下:
@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"}))
我该怎么做才能迁移此索引更改.
解决方法:
尝试指定此索引在迁移中的更改,例如(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)")
}
}