Search code examples
androidandroid-room

Should I increment the value of Room database version when migration strategy is fallback to destructive?


Should I increment the value of the Room database version if I change the content of the database when its migration strategy is set to "fallback to destructive migration"?

Following changes made to database:

  1. Some columns are removed.
  2. Content of some rows is updated in the database file that is stored in assets.

Solution

  • Yes. You should update the version of the database even with fallback to destructive migration strategy. Room uniquely identifies every database version with an "identity hash string", which is kept in a configuration table.

    Keeping the database version unchanged will cause the app to crash with an IllegalStateException. Internally Room checks the identity of the database comparing the identity hash of the current version vs the the one stored in the table called "room_master_table".

    You can learn more about this in the below article which also explains in detail how to handle version change and testing.

    Reference: https://medium.com/androiddevelopers/understanding-migrations-with-room-f01e04b07929