房间持久性迁移指标

时间:2018-09-08 15:03:11

标签: android migration android-room

晚上好。 我在向实体添加索引时遇到了麻烦。.我写了一个迁移文件,但一直说我的sql语句错误...请问有人可以帮助我吗?

这是我的实体

@Entity(tableName = "RAuditRemarksRecord",
        indices = [Index(name = "index_RAuditRemarksRecord_sheet_id",
                value = ["sheetId"],
                unique = true)])
data class RAuditRemarksRecord(@PrimaryKey(autoGenerate = true)
                               var id: Long? = null,
                               var sheetId: String = "",
                               var remarks: String = "",
                               var isDraft: Boolean = false)

这是我的迁移sql语句

database.execSQL("CREATE INDEX index_RAuditRemarksRecord_sheet_id " +
                    "ON  RAuditRemarksRecord(sheetId)")

错误:

java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /data/user/0/com.zynappse.alfamart.storeauditv2/databases/app_db
        at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55)
        at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1662)
        at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1608)
        at android.arch.persistence.db.framework.FrameworkSQLiteDatabase.execSQL(FrameworkSQLiteDatabase.java:242)
        at com.zynappse.alfamart.storeauditv2.data.DatabaseManager$MIGRATION_3_4$1.migrate(DatabaseHelper.kt:47)
        at android.arch.persistence.room.RoomOpenHelper.onUpgrade(RoomOpenHelper.java:85)
        at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onUpgrade(FrameworkSQLiteOpenHelper.java:133)
        at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:299)
        at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:194)
        at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:96)
        at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:54)
        at android.arch.persistence.room.RoomDatabase.query(RoomDatabase.java:233)
        at com.zynappse.alfamart.storeauditv2.data.dao.SyncStatusDao_Impl$5.compute(SyncStatusDao_Impl.java:311)
        at com.zynappse.alfamart.storeauditv2.data.dao.SyncStatusDao_Impl$5.compute(SyncStatusDao_Impl.java:297)
        at android.arch.lifecycle.ComputableLiveData$2.run(ComputableLiveData.java:100)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at java.lang.Thread.run(Thread.java:764)

任何帮助都会很棒。谢谢:)

ps。我已经将版本从3增加到4:)

0 个答案:

没有答案