Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RealmMigrationNeededException on fresh install after model change #1856

adamsp opened this issue Nov 29, 2015 · 4 comments

RealmMigrationNeededException on fresh install after model change #1856

adamsp opened this issue Nov 29, 2015 · 4 comments


Copy link

adamsp commented Nov 29, 2015

I'm working on integrating Realm in my Android application. My model changes from time-to-time during development, so I expect the RealmMigrationNeededException when this happens. I uninstall the app (adb uninstall, and then fresh install - but still get the exception.

I can fix it by:

adb shell run-as rm files/default.realm files/default.realm.lock

Shouldn't these be removed when I uninstall the app? I suspect this isn't a Realm issue but rather something to do with Android or adb - however I haven't had this issue with say, ORMLite. Any ideas?

Edit: I actually get this exception even if I don't change the model at all.

Copy link

zaki50 commented Nov 30, 2015

Hi @adamsp

RealmConfiguration( has deleteRealmIfMigrationNeeded method.
If you call this method when creating RealmConfiguration, Realm file will be deleted instead of throwing RealmMigrationNeededException.

RealmConfiguration config = new RealmConfiguration.Builder(context)

Does this help?

Copy link

adamsp commented Nov 30, 2015

That certainly makes things easier! I'll stick with this for now, but I still find it curious that Android doesn't appear to delete all files in the directory on an app uninstall. Hopefully this helps someone else.

@adamsp adamsp closed this as completed Nov 30, 2015
@bmunkholm bmunkholm removed the backlog label Nov 30, 2015
Copy link

adamsp commented Apr 21, 2016

5 months later I've finally figured this out as I check things off my pre-release TODO list.

This was caused by Android 6.0 auto-backup. I had to disable this for my Realm files (I'm using the default configuration):

<manifest ...
    <application ...

And res/xml/backup.xml:

<?xml version="1.0" encoding="utf-8"?>
    <exclude domain="file" path="default.realm"/>
    <exclude domain="file" path="default.realm.lock"/>

Copy link

thready commented Jan 31, 2017

Adam, I owe you a beer. I was pulling my hair out and then came across your article:

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

4 participants