大多数全新安装都可以正常工作,但在最新的应用程序更新后,很多报告都会出现此问题。两次更新之间已经有一段时间了,所以我认为这可能是由于用户在我添加架构之前从非常旧的版本更新......但其他人说他们已经从全新安装中看到了这一点。领域 Java 是realm-gradle-plugin:5.1.1
我很感激任何帮助,谢谢!
错误:
Caused by io.realm.exceptions.RealmMigrationNeededException
Migration is required due to the following errors: - Property 'Loan.loanRatePct' has been made required.
...
...onCreate (Activity.java:168)
我的迁移.java
if (oldVersion == 0) {
schema.get("Storage")
.addField("heat", String.class);
oldVersion++;
}
if (oldVersion == 1) {
schema.get("Env")
.addField("gameType", String.class);
oldVersion++;
}
if (oldVersion == 2) {
schema.get("Loan")
.addField("loanRatePct", Double.class);
schema.create("GameMode")
.addField("md", String.class)
.addField("name", String.class)
.addField("days", int.class)
.addField("term", int.class)
.addField("rate", String.class)
.addField("amount", int.class)
.addField("icon", int.class);
schema.create("Leaderboard")
.addField("score", String.class);
oldVersion++;
}
if (oldVersion == 3) {
schema.get("Leaderboard")
.addField("mode", String.class);
oldVersion++;
}
我的应用程序.java
Realm.init(getApplicationContext());
RealmConfiguration config = new RealmConfiguration.Builder()
//todo: EVERY UPDATE: is new schema needed?
.schemaVersion(4) // Must be bumped when the schema changes
.migration(new MyMigration()) // Migration to run instead of throwing an exception
.build();
Realm.setDefaultConfiguration(config);
活动.java
protected void onCreate(Bundle savedInstanceState) {
realm = Realm.getDefaultInstance();
...
}
编辑:忘记了:
贷款.java
public class Loan extends RealmObject {
String theloan;
int loan;
int loanRate;
double loanRatePct;
int loanBalance;
}