How to do database schema migrations in Android?(如何在 Android 中进行数据库模式迁移?)
问题描述
是否有在 Android 上进行数据库架构迁移的标准方法?例如,用户安装了我的 Android 应用程序的较新版本,但新版本需要对数据库架构进行更新(并且擦除用户的数据库并重新开始不是一种选择!).所以我需要在我的新版本第一次运行时运行一些 ALTER 语句和/或复制表.
Is there a standard way to do database schema migrations on Android? For example, user installs newer version of my Android app but the new version needs to make updates to the database schema (and wiping the user's database and starting over is not an option!). So I need to run some ALTER statements and/or copy tables the first time my new version runs.
推荐答案
是的,SQLiteOpenHelper 支持在不同版本的数据库模式之间迁移.
Yes SQLiteOpenHelper has support for migrating between different versions of DB schemas.
升级是通过实现来完成的
Upgrading is done by implementing
public abstract void onUpgrade (SQLiteDatabase db, int oldVersion, int newVersion)
并且还支持回滚到以前的版本:
And Rolling back to a previous version is also supported :
public abstract void onDowngrade (SQLiteDatabase db, int oldVersion, int newVersion)
这篇关于如何在 Android 中进行数据库模式迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Android 中进行数据库模式迁移?


- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01