Home > Software design >  How to solve room data integrity error due to identityHash mismatch?
How to solve room data integrity error due to identityHash mismatch?

Time:01-03

Issue: Whenever I make changes to the database or the model, I get the following Room data integrity error:

enter image description here

My understanding is that I shouldn't need to increase the version number since I am using .fallbackToDestructiveMigration().

Background:

  • I using DB Browser for SQLite (v3.12.0) to make changes to the database.
  • I frequently make changes to my app/database, which is still in development. So, I am using a .fallbackToDestructiveMigration() (enter image description here

    Step 2: Then double-click on the json file for your schema:

    enter image description here

    Step 3: Copy the identityHash in this json file:

    enter image description here

    Step 4: Open your database in DB Browser for SQLite. Click the "Browse Data" tab. Then from the drop-down menu choose "room_master_table".

    enter image description here

    Step 5: Compare the identifyHash from the json file in Android Studio to the identityHash in DB Browser for SQLite. If the hashes are different, this can be the cause of you Room data integrity error.

    Step 6: So, paste the identityHash from the Android Studio's json file into the identityHash cell in the DB Browser for SQLite.

    Step 7: Then press Ctrl Shift S to save the database.

    Step 8: Click "Close Database".

    Step 9: In your app on your phone or emulator go to "App Info" -> "Storage" -> "Clear data".

    Step 10: Then in Android Studio press "Run app".

    Problem solved... at least for me. If these steps did not help, please review these additional troubleshooting steps.

  • Related