I am getting this error while running program with Room Database
Room cannot verify the data integrity. Looks like you\'ve changed schema but forgot to updat
If you are upgrading Room version to 1.0.0-alpha9 from old version then please visit below article. Very Good Article for Migrate from old version to 1.0.0-alpha9 version.
https://medium.com/@manuelvicnt/android-room-upgrading-alpha-versions-needs-a-migration-with-kotlin-or-nonnull-7a2d140f05b9
In Room New Version 1.0.0-alpha9 Room adds support for the NOT NULL constraint.
That is going to change the schema that Room generates. Because it changes the schema, it also changes the identityHash of the DB and that is used by Room to uniquely identify every DB version. Therefore, we need a migration
I just had a similar issue in an espresso test and the only thing that fixed it was clearing data and also uninstalling the androidx test apks like:
adb uninstall androidx.test.orchestrator
adb uninstall androidx.test.services
On android phone:
Uninstall the app or Clear app data
To delete app data: Go settings -> Apps -> Select your app -> Storage -> Clear data
The uninstall (and re-install) not works in every case, so try clear data first!
This issue occurs mostly in development.
If you change your schema i.e., rename/add/modify your class containing table entity the integrity between exiting db in your previous build conflicts with new build.
clear the app data or install new build after uninstalling the previous build.
Now, The old db won't conflict with the newer one.
1:- It seems we need to update database version (increment by 1)
2nd Uninstall the app or Clear app data
android:allowBackup="true" inside AndroidManifest.xml prevents the data from being cleared even after the app is uninstalled.
Add this to your manifest:
android:allowBackup="false"
and reinstall the app.
Note: Make sure you change it back to true later on if you want auto backups.
Another solution:
Check the identityHash of your old json file and the new json file in apps\schema folder.
If the identityHash is different, it will give that error. Find out what you have changed by comparing both json files if you don't want to change anything.
Make sure you have exportSchema = true.
@Database(entities = {MyEntity.class, ...}, version = 2, exportSchema = true)
json schema file:
"formatVersion": 1,
"database": {
"version": 2,
"identityHash": "53cc5ef34d2ebd33c8518d79d27ed012",
"entities": [
{
code:
private void checkIdentity(SupportSQLiteDatabase db) {
String identityHash = null;
if (hasRoomMasterTable(db)) {
Cursor cursor = db.query(new SimpleSQLiteQuery(RoomMasterTable.READ_QUERY));
//noinspection TryFinallyCanBeTryWithResources
try {
if (cursor.moveToFirst()) {
identityHash = cursor.getString(0);
}
} finally {
cursor.close();
}
}
if (!mIdentityHash.equals(identityHash) && !mLegacyHash.equals(identityHash)) {
throw new 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.");
}
}