3

There is a birthday field in my RealmObject class which is a type of Int?. I need to change this field's type to Long?. I don't know whether I would need a migration or not.

From realm docs :

The integer types byte, short, int, and long are all mapped to long within Realm.

I have tried to install a version of the app without deleteRealmIfMigrationNeeded (meaning that Realm will try to do a migration if needed) on emulator and then changed the field from Int? to Long?. No crashes or exceptions. Also when I pulled my realm file from emulator, field's type stayed the same and still is Int?.

open class Profile : RealmObject() {

    @PrimaryKey
    var id = ""
    var email = ""
    var firstName = ""
    var lastName = ""
    var dateJoined = 0
    var gender: String? = null
    var birthday: Int? = null // I want to change this to Long?
}

What I am expecting is that I will need no migrations for this scenario. But I don't want to push the update without getting a real answer.

  • Did you set up your profile, including the `birthday` field, then change it to `Long?` and try to open the app? If it shows the correct date and you can view/edit it without crashes, then you should be fine. By the way, that flag seems to imply it'll _delete_ the object if migration is needed, not that it will migrate it itself. – TheWanderer Jan 10 '19 at 01:11
  • Yes profile was setup with the previous version of the app (version with `Int?`) and then I changed it to `Long?` and no crashes. Yes `deleteRealmIfMigrationNeeded` will not do the migration but I already have a migration code, so my theory is that if Realm needed to run a migration it would have instead of deleting the file. – Ergin Doğan Yıldız Jan 10 '19 at 01:17

1 Answers1

2

It is confirmed that there is no migration needed for this case. Do I need a migration to change type Int to Long?