Skip to content Skip to sidebar Skip to footer

Can't Downgrade Database From Version 2 To 1

Can anybody help me to solve this exception which is occurring in my code? 02-10 17:16:32.406: E/AndroidRuntime(8619): android.database.sqlite.SQLiteException: Can't downgrade data

Solution 1:

Assuming you are using Android SQLiteOpenHelper, you need to override onDowngrade if you want to be able to run your application with a database on the device with a higher version than your code can handle.

You should care about this "Database Version thing" if ever your database schema is ever going to change (and in general, there is good chance it would).

Solution 2:

Check your Database SqliteOpenHelper constructor it's last paramter should be the same if you use more than on SQLitehelper like ORM

Solution 3:

I have tried to change the SQLite version 1 to 2 because I had to increase the version to add a new column to my table(alter). And it's worked fine. Then, for fun I tried to change 2 to 1 like below:

From:

publicDatabaseHelper(Context context) {super(context, DB_NAME, null, 2);}

To:

publicDatabaseHelper(Context context) {super(context, DB_NAME, null, 1);}

Then I got this:

FATAL EXCEPTION:mainProcess:com.example.android.vocab,PID:3360android.database.sqlite.SQLiteException:Can'tdowngradedatabasefromversion2to1

As I explained before, we cannot decrease SQLite version after increased. So you need to change back to 2 or greater than 2:

publicDatabaseHelper(Context context) {
   super(context, DB_NAME, null, 2);
}

If you are trying to update your table, probably need to pass 3 not 2 and each and every time you need to update table, you need to increase the version(not decrease).

If you really want to downgrade the version you can override the onDowngrade()as @Matthieu expressed in his answer.

Post a Comment for "Can't Downgrade Database From Version 2 To 1"