I would like to use Realm, but I cannot change the column name or type.

Asked 5 months ago, Updated 5 months ago, 16 views

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.

Configuring Programs

·Create method (add new record)
·Read method (get value)
·Display the values obtained in TextView

·PrimaryKey: id(String)
·Column name: name(String), price(Long)

What do you want to do

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.



DataBase.kt Column Name and Type
MainActivity.kt Create Method Arguments and the Value of Arguments in Specified Items

android realm kotlin

2022-09-30 11:50

1 Answers

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
See the .

2022-09-30 11:50

If you have any answers or tips

© 2023 OneMinuteCode. All rights reserved.