即使在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()
}
答案 0 :(得分:0)
我认为您忘记增加数据库版本。更新数据库架构后,您必须增加数据库版本。
@Database(
entities = [SampleEntity::class],
version = 1
)
abstract class AppDatabase : RoomDatabase() {
}