I am copying data from an old .sqlite database into a new .sqlite database that I am planning on using from now on in my application. The old database contains a table of class Thing : NSManagedObject
objects with a number of properties on it.
To copy the data, I am using FMDB to query all of the rows in the old database, and then I do: Thing *thing = [NSEntityDescription insertNewObjectForEntityForName:@"Thing" inManagedObjectContext:context]
and then set each property on thing
using the row from the old database. And end with [context save:&error]
.
The copying works, and the data shows up in the app. However, when I try to add new data I get an error: UNIQUE constraint failed: ZTHINGS.Z_PK
. If I just create the new database and do not copy any data over, then new data can be written just fine.
So, there is a problem with me copying old data into the new database that is causing the primary key to be out of whack. Does anyone know what might cause this?
Aucun commentaire:
Enregistrer un commentaire