I started developing an Android app using Realm, but if I change the column name and type, the app will drop.Even if you change one of them, the app will drop.
MainActivity.kt
·Create method (add new record)
·Read method (get value)
·Display the values obtained in TextView
DataBase.kt
·PrimaryKey: id(String)
·Column name: name(String), price(Long)
Tried Realm on Kotlin+Android. - Qiita
While looking at various sites, mainly the above sites, it worked well to get the value by adding records, but I had to change it to the following because I named the column as written on the site.
name(String)→mName(String)price(Long)→mPhonetic(String)
DataBase.kt Column Name and Type
MainActivity.kt Create Method Arguments and the Value of Arguments in Specified Items
This is because the data structure and class definition of the objects already stored in the Realm file are different.
There are two solutions:
Specify deleteIfMigrationNeeded()
with the setting that if the application is not yet released and you can erase existing data, or automatically delete and regenerate the file if the data structure is different in RealmConfiguration
.Realm will automatically delete the existing file and regenerate it with the new data structure.
If the existing data cannot be erased, write the migration.This is an intentional change in the data structure to Realm, and this is the process of informing Realm of the change.
For more information
https://realm.io/docs/java/latest#migrations
See the .
© 2024 OneMinuteCode. All rights reserved.