Sqlite database onUpgrade() does not get called
Change your onUpgrade to the following
@Overridepublic void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { if(newVersion > oldVersion){ myContext.deleteDatabase(DB_NAME); } }
And also change your createDataBase() like below,
public void createDataBase() throws IOException{ boolean dbExist = checkDataBase(); if(dbExist){ // By calling this method here onUpgrade will be called on a // writable database, but only if the version number has been increased this.getWritableDatabase(); } dbExist = checkDataBase(); if(!dbExist){ //By calling this method an empty database will be created into the default system path //of the application so we will be able to overwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } }
At the end increase your database version and run it again. onUpgrade
doesn't get called till you call getReadableDatabase()
or similar functions.
Hope this helps