Ivanove
Ivanove

Reputation: 21

last version of Realm gives me problems

I worked with realm for a while using version realm 80.0 fine whitout problem, but today I upagrade my realm's file to 80.3 but it gives me this problem :

Caused by: io.realm.exceptions.RealmException: Primary key constraint broken. Value already exists: 0
            at io.realm.internal.Table.throwDuplicatePrimaryKeyException(Table.java:734)
            at io.realm.internal.Table.addEmptyRow(Table.java:380)
            at io.realm.Realm.createObject(Realm.java:941)
            at io.realm.FieldRealmProxy.createOrUpdateUsingJsonObject(FieldRealmProxy.java:448)
            at io.realm.CartRealmProxy.createOrUpdateUsingJsonObject(CartRealmProxy.java:428)
            at io.realm.ApplicationRealmProxy.createOrUpdateUsingJsonObject(ApplicationRealmProxy.java:552)

the empty row must store the value null or what ? thank's

Upvotes: 2

Views: 838

Answers (1)

geisshirt
geisshirt

Reputation: 2497

From the stack trace, it looks like you are using createObject() to create objects.

When working with primary keys, it is recommended to create the object as a standalone object first, set the primary key, and the use copyToRealm() to add/copy the object to your Realm (see also http://realm.io/docs/java/latest/#primary-keys).

Upvotes: 1

Related Questions