Ignore additional fields instead of throwing a RealmMigrationNeededException?


Is there a way to use load in a Realm database that has a different model schemas (additional fields only, never removal)?

The scenario we have is we have older clients in the wild but for newer clients, we want to expose additional fields. We are downloading a realm file and want to update that file. If that schema has a mismatch with the client, it throws a io.realm.exceptions.RealmMigrationNeededException exception.

Is there a way to ignore those new fields instead of throwing the exception?


Why don’t you write a migration code for those fields?


We currently have the schema migrations in the client code, so older clients will be broken if there is an update to the schema as they will not get the new migration.

We do not yet have a on-the-fly migration system.


You have migration code on the new client, why would the old client be broken? If they update then the migration will run.


We do not force clients in the wild to be up-to-date for Android. We have some clients running on 6-months old versions of the client-app (about 30 deploys behind).

More details about the situation.

  1. The client makes a request to the service to fetch a Realm database file.
  2. That Realm database file may have mismatching schemas as the clients.
  3. We do not send down SchemaMigrations to clients. It is part of the build for the client code right now.
  4. Once an old client gets the new realm database file, Realm.getInstance will throw an exception about mismatch schema, migration required

Edit 2:
Since the Realm.getInstance throws an exception, I consider the client “broken” at this point.

Edit 3:
Example scenario:
One field is added to the model.
Older clients do not know about this schema change.
The realm file includes this property on the model (because it is delivered via an endpoint on a service).
The older client gets the realm file (note, not JSON, but a realm file).
The older client tries to get an instance of the realm file, but the schema does not match exactly (since there is a new field).
This leads to the older client getting throwing an exception during the getInstance

Edit 4:
Just for clarification. The newer client will be fine and dandy because it will include the schema migration required to add the new field and read the database file correctly (woohoo). The problem is that old clients never get new code (because they don’t update the app, because they don’t want to?). I am hesitant of having the service send down a list of schema migrations alongside the schema because that can lead to many error cases (and the maintenance on that can get horrendous).


I don’t know why you deliver the realm database file via service, but it’s not the case to consider use Realm Cloud?