TaskTracker Android tutorial fails after schema change

I followed the TaskTracker tutorial for Android and was successful in getting everything working and syncing.

Then, I went to Realm schema for Tasks collection and added “description” property as an optional string. Then I deployed my change.

In Android code, I added the following to the Task model (which I got from SDKs tab):

var description: String? = null

Upon starting the app I get this exception:

   java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mongodb.tasktracker/com.mongodb.tasktracker.TaskActivity}: io.realm.exceptions.RealmMigrationNeededException: Migration is required due to the following errors:
    - Property 'Task.description' has been added.

The documentation states that the database automatically handles all synced schema migrations.

If that’s the case, why do I get this error? What is the fix for this?

I figured out the problem. I got a hint from another post but it wasn’t super clear what the answer was.

In TaskActivity.kt, you need to comment out the “realm = Realm.getDefaultInstance()” within onCreate().

The call to getDefaultInstance() was the cause of the migration exception. With it commented out, the call to getInstanceAsync() in onStart() happens first which uses waitForInitialRemoteData(). This migrates the data before you use it.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.