I have room setup on production app. I have made many schema related changes to multiple tables in my app.
Before shipping to production build, I have made sure of the following
- Increase database version
- have
exportSchema = false
in@Database
annotation line - allowBackup to false in manifest
<application android:allowBackup="false" />
- have
.fallbackToDestructiveMigration()
while creating database - have
.fallbackToDestructiveMigrationOnDowngrade()
while creating database - have
.enableMultiInstanceInvalidation()
while creating database
App crashes with the following stacktrace.
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.
For development I can clear app cache and data, but how to fix this in production? I do not wish to write migration steps as there are multiple changes in schema and tables.
I have read excellent article, but it's not helpful. What are my options?
stacktrace
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)