3

I've implemented database in realm on Android an iOS. I'm hardly sure that they are the same but if I'm replacing file from iOS and getting Realm instance using this file I get RealmMigrationNeededException. Is there any way to compare schemas in realm files from Android and iOS? If I'm doing the same action with file from another Android device it works.

Edit:

After adding empty Migration:

public class Migration implements RealmMigration {

    @Override
    public long execute(Realm realm, long version) {
        return version;
    }
}

I get: "Primary key not defined for field 'id' in existing Realm file. Add @PrimaryKey." Both platforms have 'id' field implemented as primary key.

Dawid Hyży
  • 3,581
  • 5
  • 26
  • 41

1 Answers1

1

There doesn't exit a tool yet that can output the entire schema unfortunately. You can use our Realm Browser for IOS, which will show you some of it, but if I remember correctly it will not show you e.g which fields are indexed: https://itunes.apple.com/us/app/realm-browser/id1007457278?mt=12

The migration exception should give you some idea what is wrong though?

Christian Melchior
  • 19,978
  • 5
  • 62
  • 53
  • In exception message i get: RealmMigration must be provided. I used "Save Model Definition" and export both(iOS & Android) to Java then i compare this using FileMerger and i get 0 differences. – Dawid Hyży Oct 28 '15 at 10:59
  • It might be better if you sent both files to help@realm.io together with your model files, then we can look at them to figure out what is wrong. – Christian Melchior Oct 28 '15 at 11:04
  • I've added empty migration to configuration and i get message: "Primary key not defined for field 'id' in existing Realm file. Add @PrimaryKey." We have added primary key for 'id' field on both platforms. – Dawid Hyży Oct 28 '15 at 11:12
  • What versions of Realm on both platforms are you using? – Christian Melchior Oct 28 '15 at 11:16
  • Android: 0.84.0, iOS: 0.96.2. What is suspicious if I use "Save Model Definition" in RealmBrowser it doesn't add @PrimaryKey annotation in the output model files. – Dawid Hyży Oct 28 '15 at 11:17
  • I've removed @PrimaryKey annotation on Android and I've import realm file from iOS successfully. Is it possible that information about primary key is not stored in realm file? We have declared appropriate fields as primary key on both platforms. – Dawid Hyży Oct 28 '15 at 12:30
  • The primary key information is stored in the Realm file. So that sounds really strange. – Christian Melchior Oct 28 '15 at 12:38
  • Is our declaration of primary key correct? + (nullable NSString *)primaryKey { return NSStringFromSelector(@selector(id)); } – Dawid Hyży Oct 28 '15 at 13:21
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/93658/discussion-between-dawid-hyzy-and-christian-melchior). – Dawid Hyży Oct 29 '15 at 09:42
  • 1
    We have discovered a critical error in how primary keys are defined: https://github.com/realm/realm-java/issues/1703 and are working to fix it. – Christian Melchior Oct 30 '15 at 11:25
  • I saw that issue is closed. When are you planning to release new version? – Dawid Hyży Nov 05 '15 at 10:05
  • You can already use it in our `0.84.2-SNAPSHOT`, but we will probably release a full `0.84.2` either Friday or Monday. – Christian Melchior Nov 05 '15 at 12:18