为什么即使在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()
    }

最佳答案

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

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

abstract class AppDatabase : RoomDatabase() {
}

07-28 01:55