Realm migration property said to have been remove was never added

361 views Asked by At

Please I have this issue with realm migration error that a property has been removed, but the issue is that I never added that property mention in the realm Object. Here is the realm Object

open class FeedbackModel(
@PrimaryKey var id : Long = -1,
var agentEmail: String? = null,
var agentName: String? = null,
var agentPhone: String? = null,
var appName: String? = null,
var comment: String? = null,
var deviceId: String? = null,
var date : String? = null,
var deviceType: String? = null,
var esaCode: String? = null,
var fepName: String? = null,
var rateValue: Int = 0
) : RealmObject()

Here is the error

: io.realm.exceptions.RealmMigrationNeededException: Migration is required due to the 
following errors:
- Property 'FeedbackModel.$stable' has been removed.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3729)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4020)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2328)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8633)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

Nothing like $stable property was added. Please how can I resolve this?

2

There are 2 answers

0
ilatyphi95 On

I noticed the same thing with realm when I initially had the class in java but migrate it to Kotlin. Even though you do not have the field ($stable) in your table, realm seems to somehow generate that className.$stable for you. So the way I solve it was that I made sure I check for it and remove it during migration process like this

val objectSchema = realm.schema.get("ClassName")

if(objectSchema.hasField("\$stable")) {
                objectSchema.removeField("\$stable")
            }

make sure you add this block of code after all other fields needed in your realm object has been added.

0
Maxim On

You can find this field with reflection

val fields = MyKotlinEntity.class.getFields()

This annotation is added on classes by the compiler when their stability is inferred. It indicates that there will be a synthetic static final int $stable added to the class which can be used by the compose compiler plugin to generate expressions to determine the stability of a realized type at runtime.

https://developer.android.com/reference/kotlin/androidx/compose/runtime/internal/StabilityInferred

I haven't found a way to hide this field yet... =(