RealmMigrationNeededException on fresh install after model change #1856

Closed
adamsp opened this Issue Nov 29, 2015 · 4 comments

Comments

Projects
None yet
4 participants
@adamsp

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 my.package.name), and then fresh install - but still get the exception.

I can fix it by:

adb shell run-as my.package.name 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.

@zaki50

This comment has been minimized.

Show comment
Hide comment
@zaki50

zaki50 Nov 30, 2015

Contributor

Hi @adamsp

RealmConfiguration(https://realm.io/docs/java/latest/api/io/realm/RealmConfiguration.html) 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)
    .deleteRealmIfMigrationNeeded()
    .build()

Does this help?

Contributor

zaki50 commented Nov 30, 2015

Hi @adamsp

RealmConfiguration(https://realm.io/docs/java/latest/api/io/realm/RealmConfiguration.html) 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)
    .deleteRealmIfMigrationNeeded()
    .build()

Does this help?

@adamsp

This comment has been minimized.

Show comment
Hide comment
@adamsp

adamsp 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 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 Nov 30, 2015

@bmunkholm bmunkholm removed the backlog label Nov 30, 2015

@adamsp

This comment has been minimized.

Show comment
Hide comment
@adamsp

adamsp 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 ...
        android:fullBackupContent="@xml/backup">
    ....
</manifest>

And res/xml/backup.xml:

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

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 ...
        android:fullBackupContent="@xml/backup">
    ....
</manifest>

And res/xml/backup.xml:

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

This comment has been minimized.

Show comment
Hide comment
@thready

thready Jan 31, 2017

Adam, I owe you a beer. I was pulling my hair out and then came across your article: http://speakman.net.nz/blog/2016/04/21/handling-realmmigrationneededexception-on-a-fresh-installation-on-android/

Thank you very much!

thready commented Jan 31, 2017

Adam, I owe you a beer. I was pulling my hair out and then came across your article: http://speakman.net.nz/blog/2016/04/21/handling-realmmigrationneededexception-on-a-fresh-installation-on-android/

Thank you very much!

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