Sanket Ranaware Sanket Ranaware - 1 month ago 10
Android Question

"realm migration needed", exception in android while retriving values from realm db

I am using Realm as a back end in my application. I have created one table named Setting. I added values in that table, by following the steps given on Realm's official site.
But when I am going to retrieve values from that table in, I getting exception


"io.realm.exceptions.RealmMigrationNeededException: RealmMigration must be provided" on the line:" realm=Realm.getInstance(getApplicationContext());".


Actually, I am new to android and Realm, so finding trouble to understand what is problem.
If anyone knows solution please help me.

Answer

EDIT: for new versions of Realm, Realm.init(Context context) is added

Realm.init(context);    
RealmConfiguration config = new RealmConfiguration
                                     .Builder()
                                     .deleteRealmIfMigrationNeeded()
                                     .build();

This will result in loss of data.

Or add a migration following the official docs:

https://realm.io/docs/java/latest/#migrations

Comments