我假设你正在使用SQLite数据库。如果是这种情况,则在此存在工作解决方案:
看到该职位rmkrishna的回答,如下:
首先检查当前的数据库版本,该数据库
private final static String DATABASE_NAME = "MainDB";
private static final int DATABASE_VERSION = 1;
public BaseSQLiteOpenHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
,并增加数据库版本(DATABASE_VERSION),并在添加新表查询升级和创建方法如下。
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("old query no need to change");
db.execSQL("Create your new table here");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion < 2) {
db.execSQL("Create your new table here as well this for update the old DB");
}
}