Handling Room Database Migrations
Understand how to handle Room database migrations for Android apps by exploring automatic and manual migration strategies. This lesson guides you through managing schema changes with Room to avoid app crashes and data loss, empowering you to maintain robust data persistence effectively.
We must perform database migrations whenever we change the table schemas—that is, modify, add, or delete a field in an existing table or add a new table. The app should gracefully handle all the database upgrades for both new and existing users. If all the upgrade scenarios aren’t handled, it may cause the app to crash or may corrupt users’ data.
Database migrations
Database migrations can either be automatic or manual. In this section, we’ll learn about both kinds of migrations.
To refresh our memories, let’s look at the MyDatabase class we defined in the “Working with Room Databases” lesson.
Our database uses the User entity, which we described in the ...