I'm doing the following inside of didFinishLaunchingWithOptions
:
let config = Realm.Configuration(
schemaVersion: 0,
deleteRealmIfMigrationNeeded: true
)
Realm.Configuration.defaultConfiguration = config
let realm = try! Realm()
Basically, while developing, I don't want to worry about migrations and just want to clear the database whenever the schema changes. My understanding is that's exactly what deleteRealmIfMigrationNeeded
is for.
The problem is that sometimes it crashes while trying to initialize Realm with the following error:
fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=5 "Directory at path '/Users/rock/Library/Developer/CoreSimulator/Devices/D626848E-14D5-47AC-8FFB-9B67D024DEF1/data/Containers/Data/Application/6F71103C-9E10-4131-BED4-D96445FABA52/Documents/default.realm' does not exist."
The default.realm file is getting removed, presumably because of deleteRealmIfMigrationNeeded
, but then isn't getting recreated (as I'd expect) when initializing Realm with that last line.
Interestingly, if I manually delete default.realm.lock
and then restart the app, it'll work.
Am I doing this wrong? Could this be a bug? (I'm using Realm Swift 2.4.1)
I just came across the same problem and the solution in my case was to turn off the Realm Browser if you have it open.
Cheers!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With