objectbox / objectbox-java

Android Database - first and fast, lightweight on-device vector database
https://objectbox.io
Apache License 2.0
4.39k stars 302 forks source link

App is crashing when new field is added in an entity #1031

Closed HassanDeveloper6 closed 2 years ago

HassanDeveloper6 commented 2 years ago

The app is crashing on startup when I try to Install the new version of the release APK. The previous version of my app is 1.2 and it's installed in the device, I've added a new field in an entity and set the versionName to 1.3 and generated a new release APK with the updated version. So when I try to Install this new version (1.3) over the previous (1.2) installed app, it's installed successfully but it's not open the app as it's crashing instantly and when I clear the app data then it's working fine.

Here's the old entity class

@Entity
data class CompanyEntity(
        @Id(assignable = true)
        var id: Long = 0,
        var code: String? = null,
        var name: String? = null)

And this is the new entity class with new field added

@Entity
data class CompanyEntity(
        @Id(assignable = true)
        var id: Long = 0,
        var code: String? = null,
        var name: String? = null,
        var discount: String? = null)

I've read the documentation where they mentioned if we add or remove the new field in an entity then migration will be handled by the object-box automatically, then why It's crashing.

Kindly help me about this issue, anticipating for a positivie response from you.

greenrobot commented 2 years ago

Please post some stack trace of the crash.

greenrobot-team commented 2 years ago

Please also check that your model file (objectbox-models\default.json) was updated successfully. And it it was not accidentally deleted and re-created (which will cause IDs to change and therefore opening the database to fail due to the model conflicting with the existing one).

no-response[bot] commented 2 years ago

Without additional information, we are unfortunately not sure how to resolve this issue. Therefore this issue has been automatically closed. Feel free to comment with additional details and we can re-open this issue.