0

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

sam80
  • 83
  • 1
  • 9
  • look here.. http://stackoverflow.com/questions/12479232/why-is-this-code-raising-the-coredata-error-19-primary-key-must-be-unique – TonyMkenu Nov 13 '12 at 15:08
  • Thanks but found this answer before. It didn't solve the problem asked. I did by checking my sqlite db and figured it out by replacing the table Z_ENT with the correct parameter. – sam80 Nov 14 '12 at 09:35

1 Answers1

0

I just experienced this same error and found a solution that I have detailed in this other SO post:

Why is this code raising the "CoreData: error: (19) PRIMARY KEY must be unique" error?

Community
  • 1
  • 1
bluebinary
  • 1,026
  • 14
  • 17