标签: core-data-migration

在非连续版本之间迁移时出现核心数据迁移错误

问题

  • 我有13个版本的核心数据模型.
  • 我制作了13种测绘模型(V1-V2,V2-V3等)
  • 我已经开启了自动迁移功能.
  • 在两个连续版本(例如V12-V13)之间的迁移中,迁移工作完美
  • 在两个非连续版本(例如V11-V13)之间迁移时,迁移失败并显示错误:

    Can't find mapping model for migration

我试过的

为每个可能的版本组合创建映射模型.这有效,但这是一个真正的麻烦.

对于版本14,我需要制作14种不同的映射模型.手动.啊.

这是我传入的用于迁移的选项:

[persistentStoreCoordinator addPersistentStoreWithType:[self storeType]
                                          configuration:nil 
                                                    URL:url 
                                                options:[NSDictionary dictionaryWithObjectsAndKeys:
                                                         [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                                                         [NSNumber numberWithBool:NO], NSReadOnlyPersistentStoreOption,
                                                         nil]
                                                  error:&error]){
Run Code Online (Sandbox Code Playgroud)

数据模型

我的数据模型非常复杂,但它是:http://dl.dropbox.com/u/136780/Engine_V2_DataModel.xcdatamodeld.zip

我现在没有在我的数据模型中使用任何版本哈希修饰符或重命名标识符.

cocoa core-data core-data-migration

6
推荐指数
1
解决办法
1318
查看次数

首次部署到IOS设备时如何解决"没有这样的表:Z_METADATA"错误

我的应用程序首次部署到IOS设备正在崩溃,因为我得到了:"'没有这样的表:Z_METADATA'"错误.我已经从我的设备复制了SQLite文件并在SQLite浏览器中打开它,我看不到其中的表格.

它似乎发生在设置数据库的代码中(我从Apple示例中获取):

 NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"CoreDataProjectTemplate.sqlite"];
[__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]  // Errors out here
Run Code Online (Sandbox Code Playgroud)

我收到错误:

Unresolved error Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)" UserInfo=0x1905e0 {NSFilePath=/var/mobile/Applications/543D2AA1-2484-4A6B-A694-DCD55B81E224/Documents/CoreDataProjectTemplate.sqlite, NSUnderlyingException=I/O error for database at /var/mobile/Applications/543D2AA1-2484-4A6B-A694-DCD55B81E224/Documents/CoreDataProjectTemplate.sqlite.  SQLite error code:1, 'no such table: Z_METADATA'}, {
    NSFilePath = "/var/mobile/Applications/543D2AA1-2484-4A6B-A694-DCD55B81E224/Documents/CoreDataProjectTemplate.sqlite";
    NSUnderlyingException = "I/O error for database at /var/mobile/Applications/543D2AA1-2484-4A6B-A694-DCD55B81E224/Documents/CoreDataProjectTemplate.sqlite.  SQLite error code:1, 'no such table: Z_METADATA'";
}
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.1 (8G4)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).
Run Code Online (Sandbox Code Playgroud)

所以我想我的问题包括:

  1. 我该如何解决这个问题? …

iphone core-data core-data-migration ios

6
推荐指数
1
解决办法
3272
查看次数

UIManagedDocument的迁移问题

我开始在我的应用程序中使用CoreData,遵循斯坦福CS193P关于使用iOS 5的新类UIManagedDocument的课程.方法本身非常简单,但我无法理解如何处理我一直在制作的模型修改.这就是我实例化我的UIManagedDocument对象的方法(在appDelegate中,以便其他所有类都可以使用它):

if (!self.database) {
    NSURL *url=[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
    url = [url URLByAppendingPathComponent:@"AppName"];

    UIManagedDocument *doc = [[UIManagedDocument alloc] initWithFileURL:url];
    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                             [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                             [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
    doc.persistentStoreOptions = options;
    self.database=doc;
    [doc release];
}
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是,每次我更改我的.xcdatamodel时,我都无法获取以前存储在文档中的所有内容以及创建任何新实例.事实上,这样做会产生以下异常:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'This NSPersistentStoreCoordinator has no persistent stores.  It cannot perform a save operation.'
Run Code Online (Sandbox Code Playgroud)

我认为设置托管文档的"选项"属性可以解决问题,但显然这还不够.有人可以帮忙吗?无法找到真正符合我的确切需求的其他问题.

core-data core-data-migration uimanageddocument

6
推荐指数
1
解决办法
1919
查看次数

使用Magical Record进行核心数据迁移

我将Core Data和MagicalRecord用于我的应用程序的数据库.

在向数据库添加新模型时,如何在不卸载应用程序的情况下迁移数据库?

core-data-migration ios ios5 magicalrecord

6
推荐指数
1
解决办法
2178
查看次数

核心数据迁移需要多长时间才能启动?

我已经看到我的iPad上的4Gb数据库在应用程序启动时成功进行核心数据迁移需要几分钟时间.现在突然,一些用户在安装新版本后报告崩溃,并且应用程序被踢出了:无法及时启动错误.

我刚刚通过恢复旧数据库进行了测试,我确信核心数据迁移可能会超过10秒.

但是其他人担心它不应该并且尝试将它带到后台,或者至少在发布时运行循环:

iPhone应用程序启动时间和Core Data迁移

这与其他条件有什么关系,例如连接到电源?或者电池电量超过50%?

更新:我通过启动设备上的应用程序(拔掉插头)而不是调试来重现崩溃.然后我尝试在连接USB的设备上启动应用程序:崩溃.然后通过调试器启动应用程序:没有崩溃(迁移大约需要4分钟.)

额外信息:我只有企业用户(大约75个),他们都有4.5Gb的数据库.有些用户升级没问题,有些用户有.如果成功,升级都需要几分钟.崩溃总是在20秒后发生.(如果再次尝试使用这些设备,它们会继续崩溃).

我按照建议将迁移放在了运行循环之外,但我仍然想知道为什么旧方法在某些设备上运行而在其他设备上运行.所有用户都在iOS 7上.

core-data core-data-migration ios

6
推荐指数
2
解决办法
1062
查看次数

CoreData迁移问题

我目前正在编写应用程序的下一个版本.

在旧版本中,没有CoreData sqlite

在新版本中,我们有一个本地CoreData sqlite数据库.

当我从头开始安装新版本的应用程序时,没有问题,商店就在那里,我可以查询.

但是,当我在具有上一版本的手机上安装应用程序时,我的查询会返回,但没有结果.

当我查看日志时,控制台中没有任何内容,并且不会返回任何错误.

   #import "CoreDataHelper.h"

@implementation CoreDataHelper
@synthesize store = _store;
@synthesize coordinator = _coordinator;


#pragma mark - 
#pragma mark - FILES
NSString *storeFileName = @"Reporting.sqlite";

#pragma mark - 
#pragma mark - PATHS
- (NSString *)applicationDocumentsDirectory {

    return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];

}

- (NSURL *)applicationStoresDirectory {

    NSURL *storesDirectory = [[NSURL fileURLWithPath:[self applicationDocumentsDirectory]]URLByAppendingPathComponent:@"Stores"];

    NSFileManager *fileManager = [NSFileManager defaultManager];

    if (![fileManager fileExistsAtPath:[storesDirectory path]]) {
        NSError *error = nil;
        if ([fileManager createDirectoryAtURL:storesDirectory
                   withIntermediateDirectories:YES
                                    attributes:nil
                                         error:&error]) {
            //File …
Run Code Online (Sandbox Code Playgroud)

sqlite core-data core-data-migration ios

6
推荐指数
1
解决办法
473
查看次数

自定义NSEntityMigrationPolicy关系

我正在尝试使用自定义进行数据库升级NSEntityMigrationPolicy.这就是我的数据模型现在的样子以及预期结果:

  A <-------->> B   ( 1 A -> many B ) 
Run Code Online (Sandbox Code Playgroud)

我想要一个新的C实体,它将"破坏"某些子集中的B类型对象:

  A <-------->> C <------->> B  ( 1 A can have many C, each C can have many B )
Run Code Online (Sandbox Code Playgroud)

NSEntityMigrationPolicy为实体A 做了一个习惯.我为每个A创建了一些C实体createDestinationInstancesForSourceInstance:entityMapping:manager:error:,但是我对如何处理A和B之间的关系感到困惑.

在文档中,他们说要用createRelationshipsForDestinationInstance某种方式来创造新的关系.但是,对于这种情况,我没有找到任何暗示性的例子.我想可能在这里可以创建A < - >> C关系,但是在目的地上下文中B可能还不存在以创建C < - >> B关系.如何进行这样的迁移?请帮忙 :)

谢谢 !

iphone core-data core-data-migration

5
推荐指数
1
解决办法
1770
查看次数

何时对核心数据模型进行版本控制

我有一个使用 Core Data 的应用程序,这是该应用程序的第一个版本。在将第一个版本上传到 App Store 之前,我是否应该为 xdatamodeld 中的未来更改做好一些准备?或者我只需要在模型发生变化的未来应用程序版本上进行模型的版本控制?

core-data objective-c core-data-migration ios

5
推荐指数
1
解决办法
1296
查看次数

核心数据轻量级迁移错误

我一直在努力让核心数据轻量级迁移工作。遇到了一个非常棘手的问题。我已经像文档和其他SO 帖子一样设置了自动轻量级迁移。然后我创建一个新版本,选择它作为当前版本,向某个实体添加一个新字段,然后运行。有错误:

迁移失败,错误为 Error Domain=NSCocoaErrorDomain Code=134140 “操作无法完成。(Cocoa 错误 134140。)” UserInfo=0xce08c10 {reason=无法找到或自动推断迁移的映射模型,

还有一个错误:

NSUnderlyingError = "Error Domain=NSCocoaErrorDomain Code=134190 \"The operation couldn\U2019t be completed. (Cocoa error 134190.)\" UserInfo=0xcdf2d00 {reason=Each property must have a unique renaming identifier}";
Run Code Online (Sandbox Code Playgroud)

我在谷歌上搜索了一段时间“每个属性必须有一个唯一的重命名标识符”,但根本没有找到任何结果。

根据此错误消息的含义,属性应该具有唯一的重命名标识符。我回到我的模型设置,发现我确实有一些完全相同的重命名标识符。

我的问题是我根本没有真正改变模型名称。我只是添加了一个新字段。我认为重命名标识符仅在尝试重命名某些内容时才有用。或者也许无论如何都需要它。如果是这样,那么为什么 XCode 不给我们任何警告或错误呢?XCode 看不应该很明显吗?

欢迎任何建议。

core-data objective-c core-data-migration

5
推荐指数
2
解决办法
849
查看次数

CoreData轻量级迁移问题

我用 Swift 5 编写了这个应用程序,并且已经在 App Store 中上线。

现在,我只想向一个现有实体添加一个新的单个布尔属性

为此,我遵循了以下步骤:

  1. 新增版本(它在其中自动创建了 Project 2.xcdatamodel 文件)
  2. 将此版本设置为默认版本
  3. 在此新版本文件中向实体添加一个属性。
  4. 将属性shouldMigrateStoreAutomaticallyshouldInferMappingModelAutomatically添加到AppDelegate类中的 NSPersistentContainer 中。

问题:

在应用程序中,我能够成功地将数据保存在 coredata 中并从任何 ViewController 中的 coredata 中检索数据,但是,如果应用程序从头打开,它无法找到以前的文件并重新创建 coredata 文件。

每当我打开应用程序时,它都会在 xCode 控制台中显示错误:

Connecting to sqlite database file at "/dev/null"
Run Code Online (Sandbox Code Playgroud)

应用程序委托代码:

// MARK: - Core Data stack

lazy var persistentContainer: NSPersistentContainer = {

let container = NSPersistentContainer(name: "Project")

let description = NSPersistentStoreDescription()
description.shouldMigrateStoreAutomatically = true
description.shouldInferMappingModelAutomatically = true
container.persistentStoreDescriptions=[description]

container.loadPersistentStores(completionHandler: { (storeDescription, …
Run Code Online (Sandbox Code Playgroud)

core-data core-data-migration ios swift

5
推荐指数
1
解决办法
1198
查看次数