Closed saeedmozaffari closed 3 years ago
We have at least one user facing the same problem: The same exception during migration even though we don't touch the affected schema. The primary key is present since the schema got added initially. We're also unable to reproduce this error.
java.lang.IllegalStateException:
Primary key property 'Event.id' has duplicate values after migration.
Realm version(s): v5.11.0 Realm Sync feature enabled: No Android Studio version: 3.4 Android Build Tools version: 28.0.3 Gradle version: 5.4 Which Android version and device(s): Android 6.0.1 on Samsung Galaxy S7 Edge
Apparently this isn't the first time this issue got reported (see #5983 and #6221).
realm-cocoa
is affected as well: https://github.com/realm/realm-cocoa/issues/5855
Hmm, yes looking at the code, this is your model class, right? https://github.com/KianIranian-STDG/iGap-Android/blob/master/app/src/main/java/net/iGap/realm/RealmRoomMessage.java#L70
And the only modification you have for the RealmRoomMessage is this one, correct? https://github.com/KianIranian-STDG/iGap-Android/blob/master/app/src/main/java/net/iGap/realm/RealmMigration.java#L35
This could indicate a bug on our end somewhere, but it is a bit unclear where.
Same issue, we have a lot of crashes on production, but we can not reproduce the problem. Schema that crashes was added two years ago, and was not changed since then.
Caused by java.lang.IllegalStateException: Primary key property 'MyClassName.id' has duplicate values after migration. at io.realm.internal.OsSharedRealm.nativeGetSharedRealm(OsSharedRealm.java) at io.realm.internal.OsSharedRealm.<init> + 49(OsSharedRealm.java:49) at io.realm.internal.OsSharedRealm.getInstance + 13(OsSharedRealm.java:13) at io.realm.BaseRealm.<init> + 88(BaseRealm.java:88) at io.realm.BaseRealm.<init> + 4(BaseRealm.java:4) at io.realm.Realm.<init> + 12(Realm.java:12)
Realm version(s): v5.11.0 Realm Sync feature enabled: No Android Studio version: 3.4.2 Android Build Tools version: 28.0.3 Gradle version: 5.1.1 Which Android version and device(s): Android 6-9, a lot of crashes on Samsung S7 with android 8
any workaround? @cmelchior
RealmObjectSchema gameInfo = schema.get("GameInfo");
gameInfo.removeField("id");
gameInfo.addField("id",int.class,FieldAttribute.PRIMARY_KEY);
at addField, it crashes with the same exception message:
Field 'id' cannot be set as primary key since there are duplicated values for field 'id' in Class 'GameInfo'
Oh that's actually quite simple. If you remove the field, then add the field, the default values will be 0
for every single int
field, and therefore it will violate the primary key constraint.
You need to create a new field (without PK constraint), transform the existing values to that field, delete the original field, rename the field to the original name, then add the primary key constraint.
I'll assume the comment from Zhuinden described the underlying problem. So I'll close this issue. If it is still relevant we probably need something that reproduces it in order to investigate.
Hi, I have following error for migration but this error is completely unusual, because never i didn't have any code for add "RealmRoomMessage.messageId" to the migration. But i have many errors like this at fabric and unfortunately can't reproduce this state for make error.
Our project is open source and this is "Migration Class"
Realm version(s): v 5.9.0 Realm Sync feature enabled: No Android Studio version: 3.4 Android Build Tools version: 27.0.3 Gradle version: 3.1.4 Which Android version and device(s): just not happen in android version 7