RunLoop RunLoop - 1 year ago 77
Android Question

Realm not auto-deleting database if migration needed

We are in development and db schema changes occur often. Since we are not live, migrations are not needed. I therefor configured Realm as follows:

RealmConfiguration config = new RealmConfiguration.Builder(context)
.deleteRealmIfMigrationNeeded() // todo remove for production

However, when the schema is changed, an exception is thrown:
RealmMigration must be provided

My understanding from the docs are that the Realm should auto-delete the db since deleteRealmIfMigrationNeeded() is present in the config, but this does not seem to be happening. Why is this occurring?

Android Studio Dependency

compile 'io.realm:realm-android:0.86.1'

Answer Source

We had a similar issue. We solved this by adding


right after


We think the configuration will be set up after Realm is called the first time. This time we don't use any Realm object so there's no exception.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download