【发布时间】:2016-12-27 08:59:38
【问题描述】:
我在 Appstore 中有基于 Realm 移动数据库的应用程序。我想准备1.1版。更新会删除用户本地数据库中的所有数据吗?
【问题讨论】:
标签: ios database app-store realm
我在 Appstore 中有基于 Realm 移动数据库的应用程序。我想准备1.1版。更新会删除用户本地数据库中的所有数据吗?
【问题讨论】:
标签: ios database app-store realm
升级不会删除您当前数据库中的任何内容。迁移是自动的。如果您需要更改当前模型中的一个或多个字段,则需要升级数据库架构版本。将此代码放入 AppDelegate 中的 application:didFinishLaunchingWithOptions: 方法中:
//Realm migration
let config = Realm.Configuration(
schemaVersion: 2, //here's the schema version you need to change
migrationBlock: { migration, oldSchemaVersion in
if (oldSchemaVersion < 2) {
//if you want to perform particular tasks
//while migrating, place your code here.
}
})
Realm.Configuration.defaultConfiguration = config
_ = try! Realm()
【讨论】:
绝对不会,它不会删除现有的数据库,这就是 Realm 支持自动/自定义迁移的原因。
【讨论】: