Please provide a Migration in the builder or call fallbackToDestructiveMigration in the builder in which case Room will re-create all of the tables
add ".fallbackToDestructiveMigration()" before build(),
If you don’t want to provide migrations and you specifically want your database to be cleared when you upgrade the version, call fallbackToDestructiveMigration
in the database builder
database = Room.databaseBuilder(context.getApplicationContext(),
UsersDatabase.class, "Sample.db")
.fallbackToDestructiveMigration()
.build();
I ran your app from GitHub and made a sample migration from ver 1 to ver 2. It turns our there's a mistake in SQL query. It should be:
static final Migration MIGRATION_1_2 = new Migration(1, 2) {
@Override
public void migrate(SupportSQLiteDatabase database) {
database.execSQL("ALTER TABLE users "
+"ADD COLUMN address TEXT");
}
};
String > TEXT
It's also preferable to make Room's database instance a singleton, and use it only in Repo/CacheManager class. Please check the gist for a complete code changes - https://gist.github.com/lomza/0f311a1b1e9c896bc58dff925d65eab2