Android Realm migrating from 1.x to 2.x

124 views Asked by At

We're trying to migrate Realm from 1.x to a 2.x version. Do we need to provide migration in this case? We would like to keep the data obviously, but I think Realm deletes it if you update the app now. We havent released the 2.x version yet so now we need to deal with migration.

2

There are 2 answers

0
Nabil Hachicha On BEST ANSWER

The Realm should be migrated automatically to the new format going from 1.x to 2.x since the file format changed.

https://blog.realm.io/realm-java-2-0-mobile-platform-support/

1
RED_ On

What behavior have you experienced when upgrading from 1.x to 2.x on a test device?

If you have deletedRealmIfMigrationNeeded() set on your RealmConfiguration then it will delete the data. You will need remove that line from your RealmConfiguration and add a migration(YourMigration.class)

I would recommend a lot of testing for this changing, and ensure you add all past database changes the migration.

See here for information on how to do a migration: https://realm.io/docs/java/latest/#migrations