realm-migration

Realm Migration of a String field inside a new RealmList

旧街凉风 提交于 2021-01-04 07:05:31
问题 Conversation class previously had a string field named "message". Now this "message" field is removed and i have added a "RealmList allMessages" inside Conversation class instead of old "message" field. ChatMessage class has a field name "messageText". How can i migrate "message" from Conversation class to "messageText" of list "allMessages"?? public class ChatMessage extends RealmObject implements Parcelable { .... private String messageText; .... } Old Conversation class. public class

Realm Migration of a String field inside a new RealmList

烈酒焚心 提交于 2021-01-04 07:04:03
问题 Conversation class previously had a string field named "message". Now this "message" field is removed and i have added a "RealmList allMessages" inside Conversation class instead of old "message" field. ChatMessage class has a field name "messageText". How can i migrate "message" from Conversation class to "messageText" of list "allMessages"?? public class ChatMessage extends RealmObject implements Parcelable { .... private String messageText; .... } Old Conversation class. public class

Transform object to list[object] in Realm ( How can i replace a list[objects] with object field in Realm? )

允我心安 提交于 2020-02-12 05:26:49
问题 I want to import existing token into tokenList as first item , for example if someone has a token="abc" after migration , i want he/she has tokenList that tokenList[0]=="abc" This is my migration code: public class RealmMigration implements io.realm.RealmMigration { . . . if (oldVersion == 3) { final RealmObjectSchema bankSchema = realmSchema.get("Bank"); final RealmObjectSchema tokenSchema = realmSchema.get("Token"); DynamicRealmObject bank = realm.createObject("Bank",1); Token token = bank

How can I get the migration to run before the app starts to run the code?

吃可爱长大的小学妹 提交于 2020-01-11 05:20:09
问题 I'm using realm.io in a swift app. This is the first time I've had to run a migration since I have an app in production. I changed one of the models and added a couple of extra fields to it. I followed the example in the documentation and then referenced the github repo's example when that didn't work. I assumed that it was probably more complex then what the example in the documentation was letting on. Here's what I have in my appdelegate.swift file: func application(application:

Create a realm object during a Realm Migration

末鹿安然 提交于 2019-12-22 05:59:07
问题 Are you able to create a realm Object during a migration? I am wanting to extract part of an existing realm object and create a new object with that data, but the migration always hangs up. Here is my migration code private class var migrationBlock: MigrationBlock { return { migration, oldSchemaVersion in if oldSchemaVersion < 1 { print("Shema Version 0") migration.enumerate(Transaction.className(), { (oldObject, newObject) -> Void in let oldDate = oldObject!["date"] as! NSDate let

How to get Number of Records using LIMIT Query in Realm Database android

末鹿安然 提交于 2019-12-22 01:05:26
问题 I have Implemented my new project with Realm Database Plugin . I have a functionality of Pagination with Number of Record as 20. So How can I fetch 20 Record using Realm Query . I searched, but did not get any solution. 回答1: I wrote an article on Realm where I specifically mention that Common mistake : attempting to paginate a RealmResults<T> or “limit the number of results in it” for no valid reason whatsoever I’ve seen people on SO attempting to paginate a RealmResults, or “how do I do a

Detect if Realm.io db needs migration - if so, destroy it

半世苍凉 提交于 2019-12-18 13:35:38
问题 I'm using Realm for caching over the not-so-long term, and have no need to keep up with schema versions or migrating any time there's a change to a data model. So, instead of crashing anytime there's a change to the data model, how can my app smartly handle the discrepancy by blowing away the default Realm and starting from scratch? Thanks in advance! 回答1: This has been working like a charm for me since Swift 2 introduced try/catch. I just call testRealmFile() from my app delegate at launch,

Migrating, but still getting crash on 'RLMException', reason: 'Migration is required

巧了我就是萌 提交于 2019-12-13 16:09:16
问题 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Realm, 1th thing { RLMRealmConfiguration *config = [RLMRealmConfiguration defaultConfiguration]; config.schemaVersion = 2; config.migrationBlock = ^(RLMMigration *migration, uint64_t oldSchemaVersion) { }; config.objectClasses = @[[User class], [UsersMenuItem class]]; [RLMRealm migrateRealm:config]; } ... } I did add a property to the user object, the docu says the new realm