7

I'd like to change field name in Realm DB migration process. It seems that changing field name is not supported, and only copy-and-remove is the only way to do.

is this correct? It consumes lots of time.

Below code is my trial to change field value to summary in copy-and-remove manner.

RealmSchema schema = realm.getSchema();
schema.get("Invoice")
.transform(new RealmObjectSchema.Function() {
    @Override
    public void apply(DynamicRealmObject obj) {
        obj.set("summary", obj.getString("value"));
    }
})
.removeField("value");
Youngjae
  • 24,352
  • 18
  • 113
  • 198

1 Answers1

11

Probably what you need is a method: renameField

Example:

RealmSchema schema = realm.getSchema();
schema.get("Invoice").renameField("value", "summary");
PiKos
  • 1,344
  • 1
  • 16
  • 15