Skip to content Skip to sidebar Skip to footer

Database Onupgrade Method Is Never Called

I'm trying to upgrade my database from version 1 to version 2. I'm assigning DATABASE_VERSION = 2 (first version was assigned too) but onUpgrade never called. May be there is an ob

Solution 1:

Local database version will always be 0 and onUpgrade will not be called, because you never called getWritableDatabase/getReadableDatabase, which will bump version and return local db.

So you need:

  1. make call getReadableDatabase(); in your contructor/oncreate, just to trigger process, in case db version is changed or
  2. manually check sdcard version, db.getVersion(); compare to current version - DATABASE_VERSION. And do what ever you need to do - upgrade or downgrade.

Post a Comment for "Database Onupgrade Method Is Never Called"