title: How to do a Realm migration in Android?
body: <p>I'm using Realms as a database in Android app. Works fine, but I've added a new label in my user model and I'm getting the error that I need to migrate my schema:</p>
  
  <pre><code>java.lang.RuntimeException: Unable to create application com.apelucy.apelucy.app.base.MyApplication: io.realm.exceptions.RealmMigrationNeededException: Migration is required due to the following errors:
                                                     - Property 'User.testRealm' has been added.
  </code></pre>
  
  <p>How can I do the migration? I've found other solutions here but I can't implement them in my code. I can't use a solution of delete and install the app. I now that work in development, but I need to update the app in production.</p>
  
  <p>My UserRespository class:</p>
  
  <pre><code>public class UserRepository {
  
      private static UserRepository sInstance = null;
      private Context mContext = null;
  
  
  
      public static UserRepository getInstance(Context context) {
          if (sInstance == null) {
              sInstance = new UserRepository();
              sInstance.mContext = context;
          }
  
          return sInstance;
      }
  
      // DATABASE Methods
  
      public void storeUser(final User user) {
          AppSingleton.getInstance().setUser(user);
  
          Realm realm = null;
          try {
              realm = Realm.getDefaultInstance();
              realm.executeTransaction(realm1 -&gt; realm1.insertOrUpdate(user));
          } finally {
              if (realm != null) {
                  realm.close();
              }
          }
      }
  
      public User retrieveUser() {
          Realm realm = null;
          User user = null;
          try {
              realm = Realm.getDefaultInstance();
              User userRealmResult = realm.where(User.class)
                      .findFirst();
  
              if (userRealmResult != null) {
                  user = realm.copyFromRealm(userRealmResult);
              }
  
          } finally {
              if (realm != null) {
                  realm.close();
              }
          }
  
          return user;
      }
  
      public void clearUser() {
          // Clear Database objects
          Realm realm = null;
          try {
              realm = Realm.getDefaultInstance();
              realm.executeTransaction(realm1 -&gt; realm1.delete(User.class));
          } finally {
              if (realm != null) {
                  realm.close();
              }
          }
      }
  }
  </code></pre>
  
  <p>Init realm in my Application:</p>
  
  <pre><code>Realm.init(this);
  </code></pre>
  
  <p>My model change:</p>
  
  <pre><code>@SerializedName("test")
  @Expose
  private String testRealm;
  </code></pre>