Android Realm Schema mismatch error

1k views Asked by At

How do you guys match your java realm objects with swift realm objects?

My realm development started with Swift so the object server contains data migrated from swift. I then created my android version using Java (with models from Realm Studio).

Swift:
class OrderItem: Object {
    @objc dynamic var id: String = ""
}

Java
public class OrderItem extends RealmObject {
//    @PrimaryKey
    private String id;
}

Error without @PrimaryKey:
Bad changeset received: Schema mismatch: 'OrderItem' has a primary key on one side, but not on the other.

Error with @PrimaryKey: 
Exception has been thrown: The following changes cannot be made in additive-only schema mode: Primary Key for class 'OrderItem' has been added.

Any ideas how to fix these errors?

1

There are 1 answers

0
EpicPandaForce On

Error without @PrimaryKey: Bad changeset received: Schema mismatch: 'OrderItem' has a primary key on one side, but not on the other.

This indicates that the schema mismatch would do a destructive schema operation, so that's not right.

Error with @PrimaryKey: Exception has been thrown: The following changes cannot be made in additive-only schema mode: Primary Key for class 'OrderItem' has been added.

This means you probably tried without @PrimaryKey beforehand, so you locally still have a schema that doesn't have primary key, so you need to wipe data of the app to delete the Realm file and then try again with @PrimaryKey.