Search code examples
realmrealm-mobile-platform

How can I clone an entire Realm?


I've created an incorrect primary key in Realm and now I wish to remove it, however the platform forbids it claiming:

The following changes cannot be made in additive-only schema mode:
- Primary Key for class 'Entry' has been removed."

This means I would need to reset the entire db. I wish to copy the records to the new database (or solve this otherwise) Any ideas?


Solution

  • The reason that only additive changes are allowed is that allowing destructive changes would make changes un-mergeable to older devices not yet upgraded. We might allow this in future by disallowing sync to older clients, but for now you will have to work around it.

    You have 2 options:

    1) Create a new Realm, like my-realm-v2 and copy all data over, with the changes needed. This would have a similar effect to disallowing synchronization to older clients.

    2) Create a new class MyClassV2 in the original Realm and just copy the class that changed.