领域 - 迁移错误
Realm - Migration error
错误:光盘上的领域比指定的领域新:v1 与 v0
我已经尝试为我的项目添加迁移代码。我看到以下错误,但不确定如何解决。我注意到需要为 RealmMigration 更新文档。我也不想删除我的数据,我需要保存它。我可能没有正确设置它,但我试图遵循文档,这对我来说对于迁移来说有点混乱。这是我的代码:
visnetawrap.realmConfiguration = new RealmConfiguration.Builder(this).build();
Realm.setDefaultConfiguration(visnetawrap.realmConfiguration);
try {
Realm tempRealmThread = Realm.getDefaultInstance();
tempRealmThread.close();
}
catch (RealmMigrationNeededException e) {
Realm.migrateRealm(visnetawrap.realmConfiguration, new RealmMigration() {
@Override
public long execute(Realm realm, long l) {
return 1;
}
});
Realm.setDefaultConfiguration(visnetawrap.realmConfiguration);
Log.d("RealmMigration", "Schema has been upgraded.");
}
您需要在迁移中反映您的更改。检查此 example,希望对您有所帮助。
错误:光盘上的领域比指定的领域新:v1 与 v0
我已经尝试为我的项目添加迁移代码。我看到以下错误,但不确定如何解决。我注意到需要为 RealmMigration 更新文档。我也不想删除我的数据,我需要保存它。我可能没有正确设置它,但我试图遵循文档,这对我来说对于迁移来说有点混乱。这是我的代码:
visnetawrap.realmConfiguration = new RealmConfiguration.Builder(this).build();
Realm.setDefaultConfiguration(visnetawrap.realmConfiguration);
try {
Realm tempRealmThread = Realm.getDefaultInstance();
tempRealmThread.close();
}
catch (RealmMigrationNeededException e) {
Realm.migrateRealm(visnetawrap.realmConfiguration, new RealmMigration() {
@Override
public long execute(Realm realm, long l) {
return 1;
}
});
Realm.setDefaultConfiguration(visnetawrap.realmConfiguration);
Log.d("RealmMigration", "Schema has been upgraded.");
}
您需要在迁移中反映您的更改。检查此 example,希望对您有所帮助。