更新时间:2023-09-21 13:15:58
您应该将所有更改都放在可以使用以下代码的onUpgrade方法中:
You should put all changes in your onUpgrade method you can use this code:
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
String sql = "ALTER TABLE " + TABLE_SECRET + " ADD COLUMN " +
"name_of_column_to_be_added" + " INTEGER";
db.execSQL(sql);
}
这将在当前数据库中添加一列.您的数据库不会丢失数据.提醒:当执行getWriteableDatabase或getReadableDatabase并且数据库版本与旧版本不同时,将调用onUpgrade.
this adds a column in your current database. Your database will not lose data. Reminder: onUpgrade will be called when getWriteableDatabase or getReadableDatabase is executed AND the version of your database is different from your older version.