Works fine for most fresh installs, but a lot of reports are coming in with this issue after the latest app update. It has been awhile between updates, so I THINK this could be caused by users updating from a very old version before I added schema...but others have said they have seen this from a fresh install. Realm Java is realm-gradle-plugin:5.1.1
I appreciate any help, thanks!
The Error:
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)
MyMigration.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++;
}
MyApplication.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);
Activity.java
protected void onCreate(Bundle savedInstanceState) {
realm = Realm.getDefaultInstance();
...
}
Edit: forgot:
Loan.java
public class Loan extends RealmObject {
String theloan;
int loan;
int loanRate;
double loanRatePct;
int loanBalance;
}
Double
means nullable double
.
double
means non-null double
.
So .addField("loanRatePct", Double.class);
should be .addField("loanRatePct", double.class);
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With