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

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

RealmMigrationNeededException on fresh install after model change #1856

adamsp opened this issue Nov 29, 2015 · 4 comments
Labels

Comments

@adamsp
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 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
Copy link
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
Copy link
Author

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
@adamsp
Copy link
Author

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
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: http://speakman.net.nz/blog/2016/04/21/handling-realmmigrationneededexception-on-a-fresh-installation-on-android/

Thank you very much!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants