【问题标题】:Core Data Migration properties offset on iOS 7iOS 7 上的核心数据迁移属性偏移
【发布时间】:2015-03-07 02:08:14
【问题描述】:

我正在从旧版本的 Core Data Model 迁移到新版本。我只是为现有实体添加一些新属性。我从本教程中获得灵感,并为我需要的未来迁移制定了渐进式迁移机制。

core-data-migration

我有一个问题只发生在iOS 7。我在 iOS 7.1.2 和 iOS 7.0.1 上进行了测试。

问题是在迁移后所有的属性都会得到这样的偏移:

迁移前:

Entity.prop1 = value1

Entity.prop2 = value2

Entity.prop3 = value3

迁移后:

Entity.prop1 = value2

Entity.prop2 = value3

Entity.prop3 = nil

我尝试使用NSEntityMigrationPolicy 手动进行迁移,没有它,它仍然是同一件事。在iOS 8 设备上运行良好。

我检查了 SQLITE

你知道为什么会这样吗?

【问题讨论】:

  • 可能是迁移是正确的,但你读错了变量...

标签: ios iphone core-data ios7


【解决方案1】:

数据库的 journal_mode 是 WAL。

问题是 sql 数据库有一个 .sql-wal 文件,该文件在迁移过程中丢失,给我留下了一个损坏的数据库。

我通过在迁移之前将日志模式从 WAL 更改为 DELETE 解决了这个问题:

NSError *WALToDELETEMigrationError = nil;
NSDictionary *options = @{NSSQLitePragmasOption: @{@"journal_mode": @"DELETE"}};

NSPersistentStoreCoordinator *tempPersistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:oldModel];

NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[LVCoreDataController FilesStoreDirectory] error:nil];

if (![tempPersistentStoreCoordinator addPersistentStoreWithType:type configuration:nil URL:sourceStoreURL options:options error:&WALToDELETEMigrationError]) {
    NSLog(@"%@", WALToDELETEMigrationError);
}

【讨论】:

    猜你喜欢
    • 2013-11-26
    • 1970-01-01
    • 1970-01-01
    • 2011-09-14
    • 1970-01-01
    • 1970-01-01
    • 2013-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多