Search code examples
androidrealm

Do I have to migrate if I change variables type - realm?


At first I had

    @SerialName("state") var state: String

Then I decided to do this - changed the type

    @SerialName("state") @BooleanString var state: Int

Do I've to do something additional in migration or am I good to go?


Solution

  • Any change of property's name, type or constraints requests a migration.

    https://realm.io/docs/java/latest/#migrations

    Multiple cases:

    • you need to migrate to keep previous database and data : create a class implementing RealmMigration and migrate what needs to
    • you don't need to migrate because you don't care : deleteRealmIfMigrationNeeded
    • you don't need to migrate because it's a fresh install : do nothing