gpt4 book ai didi

android - Room 无法验证数据完整性。如何在不编写迁移步骤的情况下修复它?

转载 作者:行者123 更新时间:2023-11-29 22:55:33 28 4
gpt4 key购买 nike

<分区>

我在生产应用程序上设置了房间。我对我的应用程序中的多个表进行了许多与架构相关的更改。

在发布到生产版本之前,我已经确定了以下内容

  1. 增加数据库版本
  2. exportSchema = false@Database注释行
  3. allowBackup to false in manifest <application android:allowBackup="false" />
  4. .fallbackToDestructiveMigration()在创建数据库时
  5. .fallbackToDestructiveMigrationOnDowngrade()在创建数据库时
  6. .enableMultiInstanceInvalidation()在创建数据库时

应用程序崩溃并出现以下堆栈跟踪。

java.lang.IllegalStateException: 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.

对于开发,我可以清除应用缓存和数据,但如何在生产中解决这个问题? 我不想写迁移步骤,因为架构和表中有多个更改。

我已阅读 excellent article ,但这没有帮助。我有哪些选择?

堆栈跟踪

Fatal Exception: java.lang.RuntimeException: Exception while computing database live data.
at androidx.room.RoomTrackingLiveData$1.run + 92(RoomTrackingLiveData.java:92)
at java.util.concurrent.ThreadPoolExecutor.runWorker + 1167(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run + 641(ThreadPoolExecutor.java:641)
at java.lang.Thread.run + 764(Thread.java:764)

///////////////////////////

Caused by java.lang.IllegalStateException: A migration from 19 to 20 was required but not found. Please provide the necessary Migration path via RoomDatabase.Builder.addMigration(Migration ...) or allow for destructive migrations via one of the RoomDatabase.Builder.fallbackToDestructiveMigration* methods.
at androidx.room.RoomOpenHelper.onUpgrade + 101(RoomOpenHelper.java:101)
at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onUpgrade + 124(FrameworkSQLiteOpenHelper.java:124)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked + 398(SQLiteOpenHelper.java:398)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase + 298(SQLiteOpenHelper.java:298)
at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase + 92(FrameworkSQLiteOpenHelper.java:92)
at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase + 53(FrameworkSQLiteOpenHelper.java:53)
at androidx.room.RoomDatabase.inTransaction + 452(RoomDatabase.java:452)
at androidx.room.RoomDatabase.assertNotSuspendingTransaction + 275(RoomDatabase.java:275)
at androidx.room.RoomDatabase.query + 304(RoomDatabase.java:304)
at androidx.room.util.DBUtil.query + 54(DBUtil.java:54)
at com.xxx.data.local.banner.BannerDao_Impl$4.call + 218(BannerDao_Impl.java:218)
at com.xxx.data.local.banner.BannerDao_Impl$4.call + 215(BannerDao_Impl.java:215)
at androidx.room.RoomTrackingLiveData$1.run + 90(RoomTrackingLiveData.java:90)
at java.util.concurrent.ThreadPoolExecutor.runWorker + 1167(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run + 641(ThreadPoolExecutor.java:641)
at java.lang.Thread.run + 764(Thread.java:764)

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