其他分享
首页 > 其他分享> > android机房迁移指标变化

android机房迁移指标变化

作者:互联网

旧实体如下:

@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)")
    }
}

标签:android-room,migration,android
来源: https://codeday.me/bug/20191109/2012836.html