`deleteRealmIfMigrationNeeded()`是否总是删除数据?或仅在存在RealmMigrationNeededException时?

时间:2019-07-15 05:22:54

标签: android realm realm-migration

https://realm.io/docs/javascript/latest/#opening-realms 领域文档说

deleteRealmIfMigrationNeeded: delete the Realm if migration is needed; this is useful under development since the data model might change often

RealmConfiguration.java中,

 * Setting this will change the behavior of how migration exceptions are handled. Instead of throwing a
 * {@link io.realm.exceptions.RealmMigrationNeededException} the on-disc Realm will be cleared and recreated
 * with the new Realm schema.

所以我的问题是,deleteRealmIfMigrationNeeded()总是在迁移时删除数据库吗?还是仅在迁移失败时将其删除?

1 个答案:

答案 0 :(得分:0)

deleteRealmIfMigrationNeeded()将在您更改领域类结构时删除应用程序架构。否则,它不会删除您的架构。