Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
686 views
in Technique[技术] by (71.8m points)

java - Can't downgrade database from version 2 to 1 even after fresh install and re-run

I'm writing an android app using SQLite DB.

I had few experiments and changed the DB version from 1 to 2.

Then my DB schema became stable and because i didn't release the app and it's for my own use

I have decided to change the version to 1 again.

I did fresh install and everything worked fine.

But then running for the second time throws this error:

06-05 10:03:35.683: E/AndroidRuntime(9010): android.database.sqlite.SQLiteException: Can't downgrade database from version 2 to 1
06-05 10:03:35.683: E/AndroidRuntime(9010):     at android.database.sqlite.SQLiteOpenHelper.onDowngrade(SQLiteOpenHelper.java:361)

Why is that, after all I did fresh install and the DB should have been removed as well. No?

How can i change the version to 1 again?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This exception is thrown on the following conditions:

  • The device that you're running the code on has a database file of version 2.
  • The code is requesting version 1 of the database (with a param to SQLiteOpenHelper constructor)
  • onDowngrade() is not overridden in your code.

You say the code worked fine the first time after a fresh install. Make sure there's no other code that would bump up the version number of the same database file to 2 again.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...