android-Realm无法迁移

android-Realm无法迁移,第1张

概述我有一个要应用迁移的Realm模型.但是,当我应用迁移时,我得到了错误Configurationscannotbedifferentifusedtoopenthesamefile.Themostlikelycauseisthatequals()andhashCode()arenotoverriddeninthemigrationclass:在我的Activity类中,配置设置为:

我有一个要应用迁移的Realm模型.但是,当我应用迁移时,我得到了错误

Configurations cannot be different if used to open the same file. The most likely cause is that equals() and hashCode() are not overrIDden in the migration class: 

在我的Activity类中,配置设置为:

realmConfiguration = new RealmConfiguration                .Builder(this)                .schemaVersion(0)                .migration(new Migration())                .build();

我使用领域实例来获取一些值.然后我使用以下方法应用迁移:

RealmConfiguration config = new RealmConfiguration.Builder(this)            .schemaVersion(1) // Must be bumped when the schema changes            .migration(new Migration()) // Migration to run            .build();Realm.setDefaultConfiguration(config);

当我这样称呼时:realm = Realm.getDefaultInstance();我收到上面的错误.我是否正确应用了迁移?

解决方法:

您的迁移应如下所示:

public class MyMigration implements Migration {    //... migration    public int hashCode() {       return MyMigration.class.hashCode();    }    public boolean equals(Object object) {       if(object == null) {            return false;        }       return object instanceof MyMigration;    }}
总结

以上是内存溢出为你收集整理的android-Realm无法迁移全部内容,希望文章能够帮你解决android-Realm无法迁移所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1090822.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存