JoseIgnacio
JoseIgnacio

Reputation: 74

Realm schema version

I have the error:

"Provided schema version 0 is less than last set version 7."

when

let realm = try! Realm()

on just one NSViewController class.

on others View Controllers is working ok.

Some help...

Upvotes: 2

Views: 6975

Answers (1)

TiM
TiM

Reputation: 15991

This means the internal schema version number of the Realm file is 7, but if you're using the default Realm Configuration object, it will still be at 0.

This would imply your Realm file has gone through multiple migrations, and even if they're complete, you still need to reflect that in the Configuration object so Realm doesn't think it needs to run another migration.

let config = Realm.Configuration(
schemaVersion: 7,
migrationBlock: { migration, oldSchemaVersion in
    // Any migration logic older Realm files may need
})

Realm.Configuration.defaultConfiguration = config

let realm = try! Realm()

Please check out the section on Migrations in the Realm docs for more information on how the migration system works. :)

Upvotes: 5

Related Questions