Search code examples
swiftrealmrealm-migration

Realm reset schema version


I'm currently in the process of writing an app that uses Realm as a database. As I'm still writing it my models have invariably changed from what I initially designed. Unfortunately every time this happens I need to update a migration block.

Is there anyway to 'reset' my Realm so that until it's actual in 'production' I don't need to worry about Migration blocks at all? It's particularly a pain with some unit tests, I do actually delete all the tables when the tests run, but I'm assuming there must be a best practice to handle this

Specifically I am working in an iOS/Swift app.


Solution

  • Yes, there is very useful solution, just type:

    var config = Realm.Configuration()
    config.deleteRealmIfMigrationNeeded = true