androidrealmrealm-migration

Does `deleteRealmIfMigrationNeeded()` always delete the data? Or only when there is an RealmMigrationNeededException?


https://realm.io/docs/javascript/latest/#opening-realms The realm documentation says

deleteRealmIfMigrationNeeded: delete the Realm if migration is needed; this is useful under development since the data model might change often

In the RealmConfiguration.java, it says

 * Setting this will change the behavior of how migration exceptions are handled. Instead of throwing a
 * {@link io.realm.exceptions.RealmMigrationNeededException} the on-disc Realm will be cleared and recreated
 * with the new Realm schema.

So my question is, does deleteRealmIfMigrationNeeded() always delete the database when there is a migration? Or does it only delete it when the migration failed?


Solution

  • deleteRealmIfMigrationNeeded() will deleted app schema when you changed your realm classes structure. otherwise it's wont delete your schema.