I am trying to use realm sync, I followed the steps in the docs, I created a schema and then copied the java object models that realm suggested in the android app, but for some properties like int, double it gives an error.
The schema:
{
"title": "Invoice",
"properties": {
"_id": {
"bsonType": "objectId"
},
"ownerId": {
"bsonType": "string"
},
"customerId": {
"bsonType": "string"
},
"date": {
"bsonType": "date"
},
"invoiceItems": {
"bsonType": "array",
"items": {
"bsonType": "object",
"properties": {
"_id": {
"bsonType": "objectId"
},
"quantity": {
"bsonType": "int"
},
"trackId": {
"bsonType": "string"
},
"unitPrice": {
"bsonType": "double"
}
}
}
},
"total": {
"bsonType": "double"
}
}
}
CASE 1: If I use int and double
public class Invoice extends RealmObject {
@PrimaryKey
private ObjectId _id;
private String ownerId;
private String customerId;
private Date date;
private double total;
RealmList<InvoiceItem> invoiceItems;
//getters, setters
}
The Error: Failed to transform received changeset: Schema mismatch: Property 'total' in class 'Invoice' is nullable on one side and not on the other.
CASE 2: If I use Integer and Double
public class Invoice extends RealmObject {
@PrimaryKey
private ObjectId _id;
private String ownerId;
private String customerId;
private Date date;
private Double total;
RealmList<InvoiceItem> invoiceItems;
//getters, setters
}
The error: E/AndroidRuntime: FATAL EXCEPTION: main Process: realm.example.mediastore, PID: 12939 java.lang.IllegalStateException: The following changes cannot be made in additive-only schema mode: - Property 'Invoice.total' has been made optional. at io.realm.internal.OsSharedRealm.nativeGetSharedRealm(Native Method) at io.realm.internal.OsSharedRealm.<init>(OsSharedRealm.java:175) at io.realm.internal.OsSharedRealm.getInstance(OsSharedRealm.java:251) at io.realm.BaseRealm.<init>(BaseRealm.java:141) at io.realm.BaseRealm.<init>(BaseRealm.java:108) at io.realm.Realm.<init>(Realm.java:159) at io.realm.Realm.createInstance(Realm.java:495) at io.realm.RealmCache.createInstance(RealmCache.java:494) at io.realm.RealmCache.doCreateRealmOrGetFromCache(RealmCache.java:461) at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:422) at io.realm.Realm.getInstance(Realm.java:424) ...
So neither is working. I don't how how to solve this.

Terminating sync, wiping the client and then re-enabling sync solved it.