Since the iOS 5 Betas I have been testing my app’s code and the lightweight migration bit for my Core Data model has been failing. I get the “no such column: FOK_REFLEXIVE” error, but strangely I get it on the first run on devices and the simulator when no older version is present. I have changed nothing since the iOS 4.x code that worked beautifully.
The full error gives no extra information about the error and after pounding my head on the table for a bit I may have narrowed down the error to a reflexive relationship in my data model. Name has a many-to-many relationship with Name via a relationship called, names. (The idea is that Rob is related to Bob and Robert, etc). Can this all of a sudden be taboo in iOS 5?
Also, does Core Data run through every version of the data model and migrate for each no matter what version of the data model the app should be using? It’s strange to get a migration error on an app being run for the very first time I would think.
Here’s the only related code although it’s Marcus Zarra’s code which I believe everyone on Earth is using.
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (persistentStoreCoordinator_ != nil) {
return persistentStoreCoordinator_;
}
NSURL *storeURL = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"Saline.sqlite"]];
NSError *error = nil;
persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil] error:&error])
{
NSLog(@"Schema changes...");
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return persistentStoreCoordinator_;
}
UPDATE: Full error follows
2011-10-20 08:14:17.700 Saline[28315:207] CoreData: error: (1) I/O error for database at /Users/rob5408/Library/Application Support/iPhone Simulator/5.0/Applications/865AD162-49BC-4809-A63A-23E6D5A5E5C4/Documents/.Saline.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3. SQLite error code:1, 'no such column: FOK_REFLEXIVE'
2011-10-20 08:14:17.731 Saline[28315:207] Schema changes...
2011-10-20 08:14:17.732 Saline[28315:207] Unresolved error Error Domain=NSCocoaErrorDomain Code=134110 "The operation couldn’t be completed. (Cocoa error 134110.)" UserInfo=0x6f7b2d0 {destinationURL=file://localhost/Users/rob5408/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/865AD162-49BC-4809-A63A-23E6D5A5E5C4/Documents/.Saline.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3, reason=Cannot migrate store in-place: I/O error for database at /Users/rob5408/Library/Application Support/iPhone Simulator/5.0/Applications/865AD162-49BC-4809-A63A-23E6D5A5E5C4/Documents/.Saline.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3. SQLite error code:1, 'no such column: FOK_REFLEXIVE', NSUnderlyingError=0x6f7cda0 "The operation couldn’t be completed. (Cocoa error 134110.)", sourceURL=file://localhost/Users/rob5408/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/865AD162-49BC-4809-A63A-23E6D5A5E5C4/Documents/Saline.sqlite}, {
NSUnderlyingError = "Error Domain=NSCocoaErrorDomain Code=134110 \"The operation couldn\U2019t be completed. (Cocoa error 134110.)\" UserInfo=0x6f75780 {NSSQLiteErrorDomain=1, NSFilePath=/Users/rob5408/Library/Application Support/iPhone Simulator/5.0/Applications/865AD162-49BC-4809-A63A-23E6D5A5E5C4/Documents/.Saline.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3, reason=I/O error for database at /Users/rob5408/Library/Application Support/iPhone Simulator/5.0/Applications/865AD162-49BC-4809-A63A-23E6D5A5E5C4/Documents/.Saline.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3. SQLite error code:1, 'no such column: FOK_REFLEXIVE', NSUnderlyingException=I/O error for database at /Users/rob5408/Library/Application Support/iPhone Simulator/5.0/Applications/865AD162-49BC-4809-A63A-23E6D5A5E5C4/Documents/.Saline.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3. SQLite error code:1, 'no such column: FOK_REFLEXIVE'}";
destinationURL = "file://localhost/Users/rob5408/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/865AD162-49BC-4809-A63A-23E6D5A5E5C4/Documents/.Saline.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3";
reason = "Cannot migrate store in-place: I/O error for database at /Users/rob5408/Library/Application Support/iPhone Simulator/5.0/Applications/865AD162-49BC-4809-A63A-23E6D5A5E5C4/Documents/.Saline.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3. SQLite error code:1, 'no such column: FOK_REFLEXIVE'";
sourceURL = "file://localhost/Users/rob5408/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/865AD162-49BC-4809-A63A-23E6D5A5E5C4/Documents/Saline.sqlite";
}
Core Data migration only migrations from the existing store to the current model. It will not go through every model type. So you need to make sure you can migration from whatever the store is in to what the current model is.
Did you actually name an attribute
FOK_REFLEXIVE? Is this perhaps a sqlite store being created by something other than Core Data?What is the full error?
A migration will only occur when there is a store to migrate. I would test to see if there is a file on disk when you get an error as that would be the only thing that would kick off a migration.
UPDATE
This really points to an existing file. Since you are running in the simulator what happens if you just look using the console?
What do you see? Or try:
Another option is to turn on SQL debug and lets see what the output is. You can do this by adding the argument
-com.apple.CoreData.SQLDebug 3to your executable and watching the console output. I would be interested in seeing the results.