This is the code I'm using to insert a new object into my Raza entity. Nothing special though. I've used this delegate method and syntax everywhere accross my app, but for some reason I can not do it on this certain entity.
-(void)guardarRaza:(NSString *)nombre guardar:(BOOL)guardar{
if (guardar) {
Raza *raza = [NSEntityDescription insertNewObjectForEntityForName:@"Raza"
inManagedObjectContext:self.managedObjectContext];
raza.nombre = nombre;
NSError *error;
if (![self.managedObjectContext save:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
[self dismissModalViewControllerAnimated:YES];
}
The problem might come from the sqlite, because we're using one version to prepopulating the started version. I've followed the raywenderlich method entitled "Core Data Tutorial: How To Preload/Import Existing Data" .
It really works smoothly with other entities, however when I insert and save on that particular one, it crashes with CoreData: error: (19) PRIMARY KEY must be unique. I've checked out the sqlite, inserted and deleted new rows manually and it just works.
Does anyone have the same problem, or rather know how to fix it. Thanks in advance