In my android app, I am storing data in database using Room Database library.I can store and get data in a single session.There is no problem in that. The problem is when I close the app and open again I am not getting the data stored in the local database.Those data are deleted.
I've searched in google and some of them said create room data database instance using databaseBuilder.But I am using that only.but I am getting this error.
This is my instance initialization.
This is my AppDtabase class ;
@Database(entities = {SelectedBuilding.class}, exportSchema =true, version=2)
public abstract class AppDatabase extends RoomDatabase {
private static AppDatabase INSTANCE;
public abstract SelectedBuildingDao myDao();
public static AppDatabase getAppDatabase(Context context){
if (INSTANCE==null){
INSTANCE= Room.databaseBuilder(context.getApplicationContext(),AppDatabase.class,"Selected_buildings")
.addMigrations(MIGRATION_1_2)
.build();
}
return INSTANCE;
}
public static void destroyInstance(){
INSTANCE=null;
}
static final Migration MIGRATION_1_2 = new Migration(1, 2) {
@Override
public void migrate(SupportSQLiteDatabase database) {
database.execSQL("ALTER TABLE selected_building ADD COLUMN Building_Id TEXT");
}
};
}
INSTANCE= Room.databaseBuilder(context.getApplicationContext(),AppDatabase.class,"Selected_area").build();
Can anyone help me to solve this issue? Thanks in Advance.