I'll try to explain my scenario as short as possible, I have read some comments on Realm GitHub Repo about this issue:

> 
> Terminating app due to uncaught exception 'RLMException', reason:
>  'Can't set primary key property 'id' to existing value 'xxxxxxx'.
> 
> 
> 

Here's my issue:

I got two classes.

**Appointment Model Class**

```
import Foundation
import RealmSwift

class Appointment: Object {

    dynamic var id = 0
    dynamic var user_id: String?
    dynamic var profile_id: String?

    let mainMeeting = List<Meeting>()
    let meetingsWithOtherInfo = List<Meeting>()

    override static func primaryKey() -> String? {
        return "id"
    }
}

```

**Meeting Model Class**

```
import Foundation
import RealmSwift

class Meeting: Object {

    dynamic var id = 0
    dynamic var name: String?
    dynamic var created_at: String?

    // other info
    dynamic var restaurant_venue: String?

    override static func primaryKey() -> String? {
        return "id"
    }
}

```

I am fetching the **Appointments** from my server API like this

```
for fetchedAppointment in allAppointmentsFromAlamofire {
    let existingAppointment: Results<(Appointment)>! = realm.objects(Appointment).filter("id = \(fetchedAppointment["id"]!)")

    let newAppointment: Appointment = Appointment()
    newAppointment.id = fetchedAppointment["id"]! as! Int
    ....

    // add data to Meeting connected to Appointment
    let newMeeting = Meeting()
    newMeeting.id = fetchedAppointment["meetings"]["id"]! as! Int
    ...

    // update or add new entry
    try! realm.write {
        print("NEW APPOINTMENT: \(newAppointment)")
        realm.add(newAppointment, update: existingAppointment.count == 0 ? false : true)
    }
}

```

The error comes out whenever the program is trying to update existing entry in realm - whenever the existingAppointment is 1. the workaround here, from what I've read from Github Realm is to delete the **override static func primaryKey()** in Meeting Class.

There is no issue if I am just adding new entries to Appointment, but again, the issue comes out if I will be updating, and the issue goes away if I remove the primaryKey() in Meeting Class ---- BUT, in other screens of my app, I really need to have that primaryKey() in Meeting Class.

My wild guess here is that every time that I need to update entries in Appointment, I should update too the Meeting. 

So, the question is: why is this happening? Is my wild guess correct? Any other way to solve this?