Когда моя база данных sqlite создается с использованием базовой модели данных, в этой строке:
if (![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error])
Я получаю сообщение об ошибке:
NSUnderlyingException=I/O SQLite error code:1, 'no such table: Z_METADATA'
Есть идеи, как это исправить?Я пытался в течение нескольких дней.База данных создается и копируется в каталог документов на моем устройстве.
Примечание:
Если УДАЛИТЬ приложение, перестроить и установить на моем устройстве - файл .sqlite устарел через два дняназад и файл .mom датирован вчера.База данных не воссоздается во время компиляции, если это необходимо?В моем проекте нет файла .sqlite, только .xcdatamodel.
Спасибо за ваше время.
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if (persistentStoreCoordinator_ != nil) {
return persistentStoreCoordinator_;
}
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [documentPaths objectAtIndex:0];
//\MOVES DATABASE TO NEW LOCATION
NSString *storePath = [documentsDirectory stringByAppendingPathComponent:@"myShoeDatabase.sqlite"];
NSFileManager *fileManager = [NSFileManager defaultManager];
// If the expected store doesn’t exist, copy the default store.
if (![fileManager fileExistsAtPath:storePath]) {
NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"myShoeDatabase" ofType:@"sqlite"];
if (defaultStorePath) {
[fileManager copyItemAtPath:defaultStorePath toPath:storePath error:NULL];
}
}
NSURL *storeURL = [NSURL fileURLWithPath:storePath];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
NSError *error = nil;
persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return persistentStoreCoordinator_;
}
enter code here