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");
Probably what you need is a method: renameField
Example:
RealmSchema schema = realm.getSchema();
schema.get("Invoice").renameField("value", "summary");
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