gpt4 book ai didi

android - 收到错误 Room 无法验证数据完整性......即使在添加 fallbackToDestructiveMigration() 之后

转载 作者:行者123 更新时间:2023-11-29 02:23:55 24 4
gpt4 key购买 nike

为什么我收到错误 Room 无法验证数据完整性。看起来您已更改架构但忘记更新版本号。您可以简单地通过增加版本号来解决此问题。 即使在 Android 中添加 .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()
}

最佳答案

我想你忘了增加数据库版本。更新数据库架构后,您必须增加数据库版本

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

abstract class AppDatabase : RoomDatabase() {
}

关于android - 收到错误 Room 无法验证数据完整性......即使在添加 fallbackToDestructiveMigration() 之后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53387024/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com