PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, April 14, 2022

[FIXED] How to overcome RealmMigrationNeededException error on android app

 April 14, 2022     kotlin, migration, realm     No comments   

Issue

When I click on launcher icon of my android app, its crashes immediately. I check logcat error, its shows Migration is required due to the following errors: - Property 'PrintJobData.jobPageCount' has been removed.I'm using Realm database and language is kotlin. How to overcome this issue.

private val realmConfig: RealmConfiguration = RealmConfiguration.Builder()

        .name("database.realm")

// .deleteRealmIfMigrationNeeded()

        .schemaVersion(1)

        .build()


private var realm: Realm = Realm.getInstance(realmConfig)

Solution

you can delete your realm if a migration is needed:

.deleteRealmIfMigrationNeeded()

or you can write a custom migration for your realm and each change you make to your database MUST be handled in migration. NOTE: remember after your changes to your database you have to update schemaVersion and also add your custom migration to RealmConfiguration.Builder() like bellow:

val config = RealmConfiguration.Builder()
        .name("yourRealmName.realm")
        .schemaVersion(2)
        .migration(CustomMigration())
        .build()

you can learn how to write migration from this and the original document



Answered By - Azin Nilchi
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing