Conflicting changes to the role x of the relationship y have been detected

The problem is this one:

MyEntity has an ID of 0 since it’s a new MyEntity.
The Group is also new and contain a reference to MyEntity.

So, MyEntity contains a list of Group which contain a reference back to MyEntity.

The problem is that MyEntity.Group.MyEntity seems to be “new and not the same” as MyEntity. When adding MyEntity to the context, it found a conflict.

To solve the problem I set Group.MyEntity to NULL and keep the reference of Group inside the list of MyEntity. When saving, MyEntity reference (ID) is set into the Group table.

I am not sure it’s the cleanest way to do it, but the problem is finally solved.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)