xcode 10 - 核心数据迁移字符串到Int

问题描述 投票:0回答:1

我有这个属性国家

它有一个属性State,它的类型为String,但应该是Int

所以我创建了一个新的数据模型版本(用绿色标记检查)

我还将此代码添加到persistentContainer:

    let container = NSPersistentContainer(name: "Exchange")
    let description = NSPersistentStoreDescription()
    description.shouldMigrateStoreAutomatically = true
    description.shouldInferMappingModelAutomatically = true
    container.persistentStoreDescriptions = [description]

但是当我更新应用程序时 - 它崩溃了:

***由于未捕获的异常'NSInternalInconsistencyException'终止应用程序,原因:'无法创建支持目录(无法创建目录)'

从我的理解 - 从String到Int的自动迁移是这个的原因......

我如何解决它?我需要手动迁移吗?

谢谢!

ios swift core-data xcode10 core-data-migration
1个回答
1
投票

您是否添加了“二进制数据”类型的任何属性?如果是,则检查该属性的属性。如果选中“允许外部存储”复选框,请取消选中它并尝试再次运行该应用。这解决了我的问题。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.