Room cannot verify the data integrity. Looks like you've changed schema but forgot to update the version number

Viewed 4630
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.

I know that I can fix this issue by increasing the version number.

I m working in a project which has lots and lots of Database works. There is a chance that I may need to change the database structure at least 50 times a day. So daily I have to increase the number by 50 or more.

If I miss to increase(if by chance) I get the above error.

I have tried .fallbackToDestructiveMigration() and exportSchema = false with some suggestion from internet surfing.

Do any of you provide me proper solution for this.

2 Answers

Having .fallbackToDestructiveMigration() is not a great option, as it may lead to data loss when you perform an actual migration in the future (after releasing it to the world).

Go to App Info -> Storage -> Clear storage. This will clear all the data and solve your problem.

Uninstall and reinstall will help only if you have set android:allowBackup="false" under your manifest. I recommend reading the docs regarding this: https://developer.android.com/guide/topics/data/autobackup

Note: Don't change the schema version number for dev/debug build purposes.

I see that almost all the answers to the issue about .fallbackToDestructiveMigration()have overlooked an important point.

We not only add ".fallbackToDestructiveMigration()" before build() like this

Room.databaseBuilder(context.applicationContext,AppDatabase::class.java,"app_database")
            .fallbackToDestructiveMigration()
            .build()

But also need upgrade your database version in your code.like this

// before upgrade
@Database(version = 1,entities = [User::class])
// after upgrade
@Database(version = 2,entities = [User::class]) 

Only finish these two steps can you solve the following issue.

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.
Related