我怎样才能弄清楚Realm是否存在

时间:2016-05-02 10:47:12

标签: android realm realm-migration

我想更改已经存在的领域数据库的Realmconfiguration。在我的应用程序中我一直在使用:

new RealmConfiguration.Builder(this).name("db10").build();

在Playstore上发布应用程序后,我发现我可以使用自定义迁移来更改已存在的数据库,如下所示:

new RealmConfiguration.Builder(context).name("db10"). schemaVersion(0).migration(new CustomMigration()).build();

但我无法更改现有数据库的Realmconfiguration。如果我尝试使用新配置打开现有数据库,我会得到:

IllegalArgumentException: Configurations cannot be different if used to open the same file. 

所以我现在要做的是   - 在具有迁移功能的设备上创建新数据库   - 检查是否有旧数据库   - 如果设备上有旧数据库,则将内容复制到新数据库并删除旧数据库

0 个答案:

没有答案
相关问题