コアデータsqliteデータベースを使用してアプリをリリースしました。私のアプリケーションの新しいバージョンでは、XCodeに私のxcdatamodel
の新しい "モデルバージョン"を作成しました。新しいバージョンでは、エンティティが削除され、いくつかの新しい属性がエンティティの1つに追加されます。新しいアプリのバージョンに更新するときコアデータ:新しいバージョンの処理方法は?
、私はこのSQLエラーを取得しています:
The model used to open the store is incompatible with the one used to create the store
どのように私はこのエラーを処理することができますか?データベース内のすべてのデータがWebからダウンロードされるので、このエラーが発生したときに現在のsqliteファイルを削除してから最初からやり直すのが最も簡単な方法ですが、データベースに再生成できないデータが含まれている場合、
SOLUTION:
私はXcodeでマッピングモデルを作成し、キーNSMigratePersistentStoresAutomaticallyOption
でaddPersistentStoreWithType:configuration:URL:options:error:
メソッドにオプション辞書を処理するために、私のpersistentStoreCoordinatorゲッターを変更しました。
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (__persistentStoreCoordinator != nil)
{
return __persistentStoreCoordinator;
}
NSURL *cacheURL = [[[NSFileManager defaultManager] URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask] lastObject];
NSURL *storeURL = [cacheURL URLByAppendingPathComponent:@"MyDatabase.sqlite"];
NSString *storePath = [storeURL path];
NSError *error = nil;
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:NSMigratePersistentStoresAutomaticallyOption];
__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;
}
マイグレーションに関するアップルのドキュメントも読む価値があります。http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/Introduction.html悲しいことに、元の質問は、コアデータがそれ自体のために把握できる軽量変換の領域を超えているように聞こえるが、スクリーンショットが正確に最新ではない場合でもマッピングモデルは完全に適切である。 – Tommy
絶対に。 :)私はよく書かれたチュートリアルをリンゴのドキュメントに書いていますが、参照するポイントは適切な場所です。 :) –