Realm migration not called

If you write let realm = try! Realm() in a view controller as an instance variable, it will be called before application: didFinishLaunchingWithOptions from Storyboard. To resolve this, you can use lazy var realm = try! Realm() instead. lazy defers creating an instance variable until the variable is accessed.


In my case schemaVersion: 1, was to low and migration block was never called. Make sure that your new version is greater then previous.

It was my first migration but I had to change it to schemaVersion: 2 and then it started working.


In multiple view controller i have let realm = try! Realm().

It seems like one of your view controllers creates Realm before application: didFinishLaunchingWithOptions, so the default configuration with migration is not set by that time.

Make sure that you configure Realm.Configuration.defaultConfiguration before any instances of Realm are created.