遇到错误,即使添加fallbackToDestructiveMigration()之后,Room仍无法验证数据完整性。

时间:2018-11-20 05:54:27

标签: android kotlin android-room

即使在Android中添加了Room cannot verify the data integrity. Looks like you've changed schema but forgot to update the version number. You can simply fix this by increasing the version number.,为什么我仍然收到错误消息.fallbackToDestructiveMigration()

private fun buildDatabase(context: Context): AppDatabase {
        val appDatabase = Room.databaseBuilder(context.applicationContext,
                AppDatabase::class.java,
                DATABASE_NAME
        )
        if (BuildConfig.DEBUG) {
            appDatabase.fallbackToDestructiveMigration()
        }
        return appDatabase.build()
    }

1 个答案:

答案 0 :(得分:0)

我认为您忘记增加数据库版本。更新数据库架构后,您必须增加数据库版本

@Database(
        entities = [SampleEntity::class],
        version = 1
)

abstract class AppDatabase : RoomDatabase() {
}