当使用核心数据模型创建了SQLite数据库,在这一行:Xcode的SQLite数据库创建无Z_METADATA
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
你可以显示你的代码来创建PSC('initWithManagedObjectModel:') – falconcreek 2010-08-20 20:02:24
SQLite持久存储数据库是如何创建的?您不能只使用任何旧的SQLite数据库,它需要采用Core Data生成的确切格式。 – 2010-08-20 21:23:45
我加了我的代码。我正在使用由核心数据创建的数据库。感谢您的关注和帮助Brad,falcon和MPelletier。 – Bryan 2010-08-20 21:50:30