Closed ldu1101 closed 5 years ago
I would guess that the error is not in the code sample you posted but in your .xcdatamodel
. It seems like you have added an relatedByAttribute
somewhere in your Person
entity that is invalid.
@iv-mexx but,i am not found relatedByAttribute in my Person entity
@ldu1101 To fix this issue you should add 'relatedByAttribute' to your entity. If you check import code, you will find that if you did it, magical record will try to find object by this attribute before create new one.
It happens because of this line
NSString *lookupKey = [[self userInfo] objectForKey:kMagicalRecordImportRelationshipLinkedByKey] ?: MR_primaryKeyNameFromString([self name]);
NSDictionary* dic=@{@"firstName":@"li",@"lastName":@"lei",@"age":@12}; // Person* importPer=[Person MR_importFromObject:dic]; [Person MR_importFromObject:dic inContext:context];
error log: Invalid value for key 'relatedByAttribute' in 'Person' entity. Remove this key or add attribute 'personID'