未能初始化应用程序的保存数据
Failed to initialize the application's saved data
我最近更改了实体内属性的类型。我之前创建了一个新模型版本的数据库。但是有些东西不能正常工作。
如果我运行这个项目,App会报错:
Failed to initialize the application's saved data
并且在控制台中写着:
2016-01-04 23:21:16.805 toRep_Management[36979:10809172] CoreData: error: -addPersistentStoreWithType:XML configuration:(null) URL:file:///Users/Tom/Library/Application%20Support/de.toEducate.toRep_Management/CocoaAppCD.storedata options:{
NSInferMappingModelAutomaticallyOption = 1;
NSMigratePersistentStoresAutomaticallyOption = 1;
} ... returned error Error Domain=NSCocoaErrorDomain Code=134140 "Persistent store migration failed, missing mapping model." UserInfo={sourceModel=() isEditable 1, entities {
Notice = "() name Notice, managedObjectClassName toRep_Management.Notice, renamingIdentifier Notice, isAbstract 0, superentity name (null), properties {\n displayEndDate = \"(), name displayEndDate, isOptional 1, isTransient 0, entity Notice, renamingIdentifier displayEndDate, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 900 , attributeValueClassName NSDate, defaultValue (null)\";\n displayStartDate = \"(), name displayStartDate, isOptional 1, isTransient 0, entity Notice, renamingIdentifier displayStartDate, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 900 , attributeValueClassName NSDate, defaultValue (null)\";\n isOnline = \"(), name isOnline, isOptional 1, isTransient 0, entity Notice, renamingIdentifier isOnline, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 800 , attributeValueClassName NSNumber, defaultValue (null)\";\n pdf = \"(), name pdf, isOptional 1, isTransient 0, entity Notice, renamingIdentifier pdf, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 1000 , attributeValueClassName NSData, defaultValue (null)\";\n pdfImage = \"(), name pdfImage, isOptional 1, isTransient 0, entity Notice, renamingIdentifier pdfImage, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 1000 , attributeValueClassName NSData, defaultValue (null)\";\n title = \"(), name title, isOptional 1, isTransient 0, entity Notice, renamingIdentifier title, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 700 , attributeValueClassName NSString, defaultValue (null)\";\n}, subentities {\n}, userInfo {\n}, versionHashModifier (null), uniquenessConstraints (\n)";
}, fetch request templates {
}, destinationModel=() isEditable 0, entities {
Notice = "() name Notice, managedObjectClassName toRep_Management.Notice, renamingIdentifier Notice, isAbstract 0, superentity name (null), properties {\n displayEndDate = \"(), name displayEndDate, isOptional 1, isTransient 0, entity Notice, renamingIdentifier displayEndDate, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 900 , attributeValueClassName NSDate, defaultValue (null)\";\n displayStartDate = \"(), name displayStartDate, isOptional 1, isTransient 0, entity Notice, renamingIdentifier displayStartDate, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 900 , attributeValueClassName NSDate, defaultValue (null)\";\n isOnline = \"(), name isOnline, isOptional 1, isTransient 0, entity Notice, renamingIdentifier isOnline, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 800 , attributeValueClassName NSNumber, defaultValue (null)\";\n pdf = \"(), name pdf, isOptional 1, isTransient 0, entity Notice, renamingIdentifier pdf, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 1000 , attributeValueClassName NSData, defaultValue (null)\";\n pdfImage = \"(), name pdfImage, isOptional 1, isTransient 0, entity Notice, renamingIdentifier pdfImage, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 1800 , attributeValueClassName (null), defaultValue (null)\";\n title = \"(), name title, isOptional 1, isTransient 0, entity Notice, renamingIdentifier title, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 700 , attributeValueClassName NSString, defaultValue (null)\";\n}, subentities {\n}, userInfo {\n}, versionHashModifier (null), uniquenessConstraints (\n)";
}, fetch request templates {
}, reason=Can't find or automatically infer mapping model for migration, NSUnderlyingError=0x6080000511c0 {Error Domain=NSCocoaErrorDomain Code=134190 "(null)" UserInfo={entity=Notice, property=pdfImage, reason=Source and destination attribute types are incompatible}}} with userInfo dictionary {
NSUnderlyingError = "Error Domain=NSCocoaErrorDomain Code=134190 \"(null)\" UserInfo={entity=Notice, property=pdfImage, reason=Source and destination attribute types are incompatible}";
destinationModel = "() isEditable 0, entities {\n Notice = \"() name Notice, managedObjectClassName toRep_Management.Notice, renamingIdentifier Notice, isAbstract 0, superentity name (null), properties {\n displayEndDate = \"(), name displayEndDate, isOptional 1, isTransient 0, entity Notice, renamingIdentifier displayEndDate, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 900 , attributeValueClassName NSDate, defaultValue (null)\";\n displayStartDate = \"(), name displayStartDate, isOptional 1, isTransient 0, entity Notice, renamingIdentifier displayStartDate, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 900 , attributeValueClassName NSDate, defaultValue (null)\";\n isOnline = \"(), name isOnline, isOptional 1, isTransient 0, entity Notice, renamingIdentifier isOnline, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 800 , attributeValueClassName NSNumber, defaultValue (null)\";\n pdf = \"(), name pdf, isOptional 1, isTransient 0, entity Notice, renamingIdentifier pdf, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 1000 , attributeValueClassName NSData, defaultValue (null)\";\n pdfImage = \"(), name pdfImage, isOptional 1, isTransient 0, entity Notice, renamingIdentifier pdfImage, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 1800 , attributeValueClassName (null), defaultValue (null)\";\n title = \"(), name title, isOptional 1, isTransient 0, entity Notice, renamingIdentifier title, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 700 , attributeValueClassName NSString, defaultValue (null)\";\n}, subentities {\n}, userInfo {\n}, versionHashModifier (null), uniquenessConstraints (\n)\";\n}, fetch request templates {\n}";
reason = "Can't find or automatically infer mapping model for migration";
sourceModel = "() isEditable 1, entities {\n Notice = \"() name Notice, managedObjectClassName toRep_Management.Notice, renamingIdentifier Notice, isAbstract 0, superentity name (null), properties {\n displayEndDate = \"(), name displayEndDate, isOptional 1, isTransient 0, entity Notice, renamingIdentifier displayEndDate, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 900 , attributeValueClassName NSDate, defaultValue (null)\";\n displayStartDate = \"(), name displayStartDate, isOptional 1, isTransient 0, entity Notice, renamingIdentifier displayStartDate, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 900 , attributeValueClassName NSDate, defaultValue (null)\";\n isOnline = \"(), name isOnline, isOptional 1, isTransient 0, entity Notice, renamingIdentifier isOnline, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 800 , attributeValueClassName NSNumber, defaultValue (null)\";\n pdf = \"(), name pdf, isOptional 1, isTransient 0, entity Notice, renamingIdentifier pdf, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 1000 , attributeValueClassName NSData, defaultValue (null)\";\n pdfImage = \"(), name pdfImage, isOptional 1, isTransient 0, entity Notice, renamingIdentifier pdfImage, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 1000 , attributeValueClassName NSData, defaultValue (null)\";\n title = \"(), name title, isOptional 1, isTransient 0, entity Notice, renamingIdentifier title, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 700 , attributeValueClassName NSString, defaultValue (null)\";\n}, subentities {\n}, userInfo {\n}, versionHashModifier (null), uniquenessConstraints (\n)\";\n}, fetch request templates {\n}";
}
这让我很困惑。我还尝试在 AppDelegate.swift 中设置轻量级迁移,如下所示:
lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator = {
// The persistent store coordinator for the application. This implementation creates and returns a coordinator, having added the store for the application to it. (The directory for the store is created, if necessary.) This property is optional since there are legitimate error conditions that could cause the creation of the store to fail.
let fileManager = NSFileManager.defaultManager()
var failError: NSError? = nil
var shouldFail = false
var failureReason = "There was an error creating or loading the application's saved data."
// Make sure the application files directory is there
do {
let properties = try self.applicationDocumentsDirectory.resourceValuesForKeys([NSURLIsDirectoryKey])
if !properties[NSURLIsDirectoryKey]!.boolValue {
failureReason = "Expected a folder to store application data, found a file \(self.applicationDocumentsDirectory.path)."
shouldFail = true
}
} catch {
let nserror = error as NSError
if nserror.code == NSFileReadNoSuchFileError {
do {
try fileManager.createDirectoryAtPath(self.applicationDocumentsDirectory.path!, withIntermediateDirectories: true, attributes: nil)
} catch {
failError = nserror
}
} else {
failError = nserror
}
}
// Create the coordinator and store
var coordinator: NSPersistentStoreCoordinator? = nil
let migrateOptions = [NSMigratePersistentStoresAutomaticallyOption: true, NSInferMappingModelAutomaticallyOption: true]
if failError == nil {
coordinator = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)
let url = self.applicationDocumentsDirectory.URLByAppendingPathComponent("CocoaAppCD.storedata")
do {
try coordinator!.addPersistentStoreWithType(NSXMLStoreType, configuration: nil, URL: url, options: migrateOptions)
} catch {
failError = error as NSError
}
}
if shouldFail || (failError != nil) {
// Report any error we got.
var dict = [String: AnyObject]()
dict[NSLocalizedDescriptionKey] = "Failed to initialize the application's saved data"
dict[NSLocalizedFailureReasonErrorKey] = failureReason
if failError != nil {
dict[NSUnderlyingErrorKey] = failError
}
let error = NSError(domain: "YOUR_ERROR_DOMAIN", code: 9999, userInfo: dict)
NSApplication.sharedApplication().presentError(error)
abort()
} else {
return coordinator!
}
}()
有人可以帮助我吗?我认为我未能创建适当的轻量级迁移。这个假设是否正确以及如何做到这一点?
非常感谢!
I recently changed the type of an attribute inside an entity.
这是你的问题。自动迁移不支持更改属性类型。 Core Data 没有 general-purpose 方法来确定您希望如何将某些属性类型转换为其他一些属性类型,因此您不能要求它自动迁移。
有关自动轻量级迁移功能的完整说明,请参阅 Apple's documentation on the topic。
此时您可以执行以下操作之一:
- 为 non-lightweight 迁移创建映射模型
- 删除您的应用并重新安装(如果它仍在开发中,而不是如果它已经发布给用户)。
- 撤消更改并接受它。
如果您的代码正确,您可以尝试删除应用程序,然后为我构建 again.It 的作品
我的回答和汤姆一样
对于在 2021 年寻求回复的青少年:
常见问题是您创建的属性多于您在自己的代码中使用的属性。
检查一下,我遇到了同样的问题。
我最近更改了实体内属性的类型。我之前创建了一个新模型版本的数据库。但是有些东西不能正常工作。 如果我运行这个项目,App会报错:
Failed to initialize the application's saved data
并且在控制台中写着:
2016-01-04 23:21:16.805 toRep_Management[36979:10809172] CoreData: error: -addPersistentStoreWithType:XML configuration:(null) URL:file:///Users/Tom/Library/Application%20Support/de.toEducate.toRep_Management/CocoaAppCD.storedata options:{ NSInferMappingModelAutomaticallyOption = 1; NSMigratePersistentStoresAutomaticallyOption = 1; } ... returned error Error Domain=NSCocoaErrorDomain Code=134140 "Persistent store migration failed, missing mapping model." UserInfo={sourceModel=() isEditable 1, entities { Notice = "() name Notice, managedObjectClassName toRep_Management.Notice, renamingIdentifier Notice, isAbstract 0, superentity name (null), properties {\n displayEndDate = \"(), name displayEndDate, isOptional 1, isTransient 0, entity Notice, renamingIdentifier displayEndDate, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 900 , attributeValueClassName NSDate, defaultValue (null)\";\n displayStartDate = \"(), name displayStartDate, isOptional 1, isTransient 0, entity Notice, renamingIdentifier displayStartDate, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 900 , attributeValueClassName NSDate, defaultValue (null)\";\n isOnline = \"(), name isOnline, isOptional 1, isTransient 0, entity Notice, renamingIdentifier isOnline, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 800 , attributeValueClassName NSNumber, defaultValue (null)\";\n pdf = \"(), name pdf, isOptional 1, isTransient 0, entity Notice, renamingIdentifier pdf, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 1000 , attributeValueClassName NSData, defaultValue (null)\";\n pdfImage = \"(), name pdfImage, isOptional 1, isTransient 0, entity Notice, renamingIdentifier pdfImage, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 1000 , attributeValueClassName NSData, defaultValue (null)\";\n title = \"(), name title, isOptional 1, isTransient 0, entity Notice, renamingIdentifier title, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 700 , attributeValueClassName NSString, defaultValue (null)\";\n}, subentities {\n}, userInfo {\n}, versionHashModifier (null), uniquenessConstraints (\n)"; }, fetch request templates { }, destinationModel=() isEditable 0, entities { Notice = "() name Notice, managedObjectClassName toRep_Management.Notice, renamingIdentifier Notice, isAbstract 0, superentity name (null), properties {\n displayEndDate = \"(), name displayEndDate, isOptional 1, isTransient 0, entity Notice, renamingIdentifier displayEndDate, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 900 , attributeValueClassName NSDate, defaultValue (null)\";\n displayStartDate = \"(), name displayStartDate, isOptional 1, isTransient 0, entity Notice, renamingIdentifier displayStartDate, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 900 , attributeValueClassName NSDate, defaultValue (null)\";\n isOnline = \"(), name isOnline, isOptional 1, isTransient 0, entity Notice, renamingIdentifier isOnline, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 800 , attributeValueClassName NSNumber, defaultValue (null)\";\n pdf = \"(), name pdf, isOptional 1, isTransient 0, entity Notice, renamingIdentifier pdf, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 1000 , attributeValueClassName NSData, defaultValue (null)\";\n pdfImage = \"(), name pdfImage, isOptional 1, isTransient 0, entity Notice, renamingIdentifier pdfImage, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 1800 , attributeValueClassName (null), defaultValue (null)\";\n title = \"(), name title, isOptional 1, isTransient 0, entity Notice, renamingIdentifier title, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 700 , attributeValueClassName NSString, defaultValue (null)\";\n}, subentities {\n}, userInfo {\n}, versionHashModifier (null), uniquenessConstraints (\n)"; }, fetch request templates { }, reason=Can't find or automatically infer mapping model for migration, NSUnderlyingError=0x6080000511c0 {Error Domain=NSCocoaErrorDomain Code=134190 "(null)" UserInfo={entity=Notice, property=pdfImage, reason=Source and destination attribute types are incompatible}}} with userInfo dictionary { NSUnderlyingError = "Error Domain=NSCocoaErrorDomain Code=134190 \"(null)\" UserInfo={entity=Notice, property=pdfImage, reason=Source and destination attribute types are incompatible}"; destinationModel = "() isEditable 0, entities {\n Notice = \"() name Notice, managedObjectClassName toRep_Management.Notice, renamingIdentifier Notice, isAbstract 0, superentity name (null), properties {\n displayEndDate = \"(), name displayEndDate, isOptional 1, isTransient 0, entity Notice, renamingIdentifier displayEndDate, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 900 , attributeValueClassName NSDate, defaultValue (null)\";\n displayStartDate = \"(), name displayStartDate, isOptional 1, isTransient 0, entity Notice, renamingIdentifier displayStartDate, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 900 , attributeValueClassName NSDate, defaultValue (null)\";\n isOnline = \"(), name isOnline, isOptional 1, isTransient 0, entity Notice, renamingIdentifier isOnline, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 800 , attributeValueClassName NSNumber, defaultValue (null)\";\n pdf = \"(), name pdf, isOptional 1, isTransient 0, entity Notice, renamingIdentifier pdf, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 1000 , attributeValueClassName NSData, defaultValue (null)\";\n pdfImage = \"(), name pdfImage, isOptional 1, isTransient 0, entity Notice, renamingIdentifier pdfImage, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 1800 , attributeValueClassName (null), defaultValue (null)\";\n title = \"(), name title, isOptional 1, isTransient 0, entity Notice, renamingIdentifier title, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 700 , attributeValueClassName NSString, defaultValue (null)\";\n}, subentities {\n}, userInfo {\n}, versionHashModifier (null), uniquenessConstraints (\n)\";\n}, fetch request templates {\n}"; reason = "Can't find or automatically infer mapping model for migration"; sourceModel = "() isEditable 1, entities {\n Notice = \"() name Notice, managedObjectClassName toRep_Management.Notice, renamingIdentifier Notice, isAbstract 0, superentity name (null), properties {\n displayEndDate = \"(), name displayEndDate, isOptional 1, isTransient 0, entity Notice, renamingIdentifier displayEndDate, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 900 , attributeValueClassName NSDate, defaultValue (null)\";\n displayStartDate = \"(), name displayStartDate, isOptional 1, isTransient 0, entity Notice, renamingIdentifier displayStartDate, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 900 , attributeValueClassName NSDate, defaultValue (null)\";\n isOnline = \"(), name isOnline, isOptional 1, isTransient 0, entity Notice, renamingIdentifier isOnline, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 800 , attributeValueClassName NSNumber, defaultValue (null)\";\n pdf = \"(), name pdf, isOptional 1, isTransient 0, entity Notice, renamingIdentifier pdf, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 1000 , attributeValueClassName NSData, defaultValue (null)\";\n pdfImage = \"(), name pdfImage, isOptional 1, isTransient 0, entity Notice, renamingIdentifier pdfImage, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 1000 , attributeValueClassName NSData, defaultValue (null)\";\n title = \"(), name title, isOptional 1, isTransient 0, entity Notice, renamingIdentifier title, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 700 , attributeValueClassName NSString, defaultValue (null)\";\n}, subentities {\n}, userInfo {\n}, versionHashModifier (null), uniquenessConstraints (\n)\";\n}, fetch request templates {\n}"; }
这让我很困惑。我还尝试在 AppDelegate.swift 中设置轻量级迁移,如下所示:
lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator = {
// The persistent store coordinator for the application. This implementation creates and returns a coordinator, having added the store for the application to it. (The directory for the store is created, if necessary.) This property is optional since there are legitimate error conditions that could cause the creation of the store to fail.
let fileManager = NSFileManager.defaultManager()
var failError: NSError? = nil
var shouldFail = false
var failureReason = "There was an error creating or loading the application's saved data."
// Make sure the application files directory is there
do {
let properties = try self.applicationDocumentsDirectory.resourceValuesForKeys([NSURLIsDirectoryKey])
if !properties[NSURLIsDirectoryKey]!.boolValue {
failureReason = "Expected a folder to store application data, found a file \(self.applicationDocumentsDirectory.path)."
shouldFail = true
}
} catch {
let nserror = error as NSError
if nserror.code == NSFileReadNoSuchFileError {
do {
try fileManager.createDirectoryAtPath(self.applicationDocumentsDirectory.path!, withIntermediateDirectories: true, attributes: nil)
} catch {
failError = nserror
}
} else {
failError = nserror
}
}
// Create the coordinator and store
var coordinator: NSPersistentStoreCoordinator? = nil
let migrateOptions = [NSMigratePersistentStoresAutomaticallyOption: true, NSInferMappingModelAutomaticallyOption: true]
if failError == nil {
coordinator = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)
let url = self.applicationDocumentsDirectory.URLByAppendingPathComponent("CocoaAppCD.storedata")
do {
try coordinator!.addPersistentStoreWithType(NSXMLStoreType, configuration: nil, URL: url, options: migrateOptions)
} catch {
failError = error as NSError
}
}
if shouldFail || (failError != nil) {
// Report any error we got.
var dict = [String: AnyObject]()
dict[NSLocalizedDescriptionKey] = "Failed to initialize the application's saved data"
dict[NSLocalizedFailureReasonErrorKey] = failureReason
if failError != nil {
dict[NSUnderlyingErrorKey] = failError
}
let error = NSError(domain: "YOUR_ERROR_DOMAIN", code: 9999, userInfo: dict)
NSApplication.sharedApplication().presentError(error)
abort()
} else {
return coordinator!
}
}()
有人可以帮助我吗?我认为我未能创建适当的轻量级迁移。这个假设是否正确以及如何做到这一点?
非常感谢!
I recently changed the type of an attribute inside an entity.
这是你的问题。自动迁移不支持更改属性类型。 Core Data 没有 general-purpose 方法来确定您希望如何将某些属性类型转换为其他一些属性类型,因此您不能要求它自动迁移。
有关自动轻量级迁移功能的完整说明,请参阅 Apple's documentation on the topic。
此时您可以执行以下操作之一:
- 为 non-lightweight 迁移创建映射模型
- 删除您的应用并重新安装(如果它仍在开发中,而不是如果它已经发布给用户)。
- 撤消更改并接受它。
如果您的代码正确,您可以尝试删除应用程序,然后为我构建 again.It 的作品
我的回答和汤姆一样
对于在 2021 年寻求回复的青少年: 常见问题是您创建的属性多于您在自己的代码中使用的属性。
检查一下,我遇到了同样的问题。