1

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?

jscs
  • 63,694
  • 13
  • 151
  • 195
  • Have you tried adding `@PrimaryKey` then running `clear data` on the Android emulator you're using? – EpicPandaForce Mar 04 '18 at 12:43
  • @EpicPandaForce clearing/wiping the data worked! Thanks! Additional info for us Realm newbies, (@Primary @Required) causes schema errors when entering new RealmObjects into the project. Clearing data on the emulator fixes all of them. – carldevelopsforcoffee Mar 05 '18 at 00:08

1 Answers1

1

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.

EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428