Peter Lapisu
Peter Lapisu

Reputation: 20965

Migrating, but still getting crash on 'RLMException', reason: 'Migration is required

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Realm, 1th thing
    {
        RLMRealmConfiguration *config = [RLMRealmConfiguration defaultConfiguration];
        config.schemaVersion = 2;
        config.migrationBlock = ^(RLMMigration *migration, uint64_t oldSchemaVersion) {

        };
        config.objectClasses = @[[User class], [UsersMenuItem class]];
        [RLMRealm migrateRealm:config];
    }

    ...
}

I did add a property to the user object, the docu says the new realm should automigrate, but i get a crash

*** Terminating app due to uncaught exception 'RLMException', reason: 'Migration is required for object type 'User' due to the following errors:
- Property 'realtedMenuItems' has been added to latest object model.'
*** First throw call stack:
(0x1838ad900 0x182f1bf80 0x10015db3c 0x10014aa60 0x100149a70 0x100116500 0x1000a6488 0x1000f1664 0x1885a00c0 0x18859fcc4 0x100039568 0x188615704 0x188844130 0x1888484b8 0x1888455c0 0x184e63790 0x184e63b10 0x183864efc 0x183864990 0x183862690 0x183791680 0x18860e580 0x188608d90 0x1000b7430 0x1833328b8)
libc++abi.dylib: terminating with uncaught exception of type NSException

Version: 0.95

Note: When i updated to 0.96 i get

*** Terminating app due to uncaught exception 'RLMException', reason: 'Provided schema version 0 is less than last set version 3.'
*** First throw call stack:

Upvotes: 3

Views: 1155

Answers (2)

marius
marius

Reputation: 7806

RLMRealmConfiguration acts as value object. Modifications applied to it, don't automatically take effect to the defaultConfiguration. You can only retrieve a copy of it. That means you have to user the setter to share you modifications back.

Upvotes: 1

Peter Lapisu
Peter Lapisu

Reputation: 20965

Looks like adding

[RLMRealmConfiguration setDefaultConfiguration:config];

solved the issue, although not sure why

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Realm
    {
        RLMRealmConfiguration *config = [RLMRealmConfiguration defaultConfiguration];
        config.schemaVersion = 4;
        config.migrationBlock = ^(RLMMigration *migration, uint64_t oldSchemaVersion) {

        };
        NSError * error = [RLMRealm migrateRealm:config];
        if (error) {
            NSLog(@"Error migrating realm %@", error);
        }
        [RLMRealmConfiguration setDefaultConfiguration:config];
    }

Upvotes: 1

Related Questions