I have been doing extensive research over the past day to solve the error I have come across, but have been unable to find solutions to my problem. My app is designed to recording data as "datapoints" in a "recording" and store these objects in core data. After a recording finishes (all of the datapoints and the recording itself have already been created and added to the MOC) I save the context:
- (void)saveContext
{
NSError *error;
if (self.managedObjectContext != nil) {
if ([self.managedObjectContext hasChanges] && ![self.managedObjectContext save:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
}
Again, I have used this exact code in previous projects and it has worked without a hitch. However, with this project the app calls the abort() function in - (void)savecontext. When abort() is called, the following error is displayed:
CoreData: error: (19) PRIMARY KEY must be unique
Unresolved error Error Domain=NSCocoaErrorDomain Code=19 "The operation couldn’t be completed. (Cocoa error 19.)" UserInfo=0x155c6850 {NSSQLiteErrorDomain=19, NSUnderlyingException=error during SQL execution : PRIMARY KEY must be unique, NSFilePath=/var/mobile/Containers/Data/Application/9C5CB2CF-70C3-462B-BD26-E75AC4AF22E5/Documents/APPNAME.sqlite}, {
NSFilePath = "/var/mobile/Containers/Data/Application/9C5CB2CF-70C3-462B-BD26-E75AC4AF22E5/Documents/APPNAME.sqlite";
NSSQLiteErrorDomain = 19;
NSUnderlyingException = "error during SQL execution : PRIMARY KEY must be unique";
}
Midway through the project, I changed the name of one of the entities. However, I doubt this is the source of the problem, because when this problem arose I remade the entire data model and all of the categories from scratch, and it changed nothing.
In my research, I found that this error is very common in apps which pre-populate their SQLite files with data to load into the app. This is not the case with my app, however, and so I found all of the solutions to this problem on Stack Exchange to be unhelpful, as they all focused on editing this pre-existing file.
I'm also relatively new to Stack Exchange, so if there is any piece of information which I excluded, please let me know and I'll add it. Thanks for any help you can give.
Aucun commentaire:
Enregistrer un commentaire