在我的應用程序中,我有一個核心數據實體,其屬性爲value
。我想在即將發佈的版本中將此屬性的類型從Integer 16
更改爲Transformable
。核心數據從整數16遷移到可轉換
現在,建立我的持久存儲協調的時候,我包括以下內容的選項:我已經建立了我的核心數據模型的第二個版本,其中包括更新到value
屬性
let options: [NSString: Bool] = [
NSMigratePersistentStoresAutomaticallyOption: true,
NSInferMappingModelAutomaticallyOption: true]
try coordinator!.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: options) ...
現在,並沒有其他變化。當我學嘗試構建,我得到以下錯誤:
CoreData: error: -addPersistentStoreWithType:SQLite ... Persistent store migration failed, missing mapping model
進一步回落,這一點:
Can't find or automatically infer mapping model for migration ... Source and destination attribute types are incompatible.
因此很明顯,CoreData不能從整數16映射到自動變形?我該如何解決這個問題?
您還可以按順序鏈接多個輕量級遷移,以執行更復雜的遷移,而無需通過重量級路徑。在這種情況下,您可以執行Tom在第二部分中提出的建議,並創建使用整數值中的數據的第二個屬性,並刪除整數值屬性。然後,您可以進行後續輕量級遷移,將valueBlob屬性重命名爲value。這對於這個特定的例子來說可能是過分的,但對於避免重量級遷移路徑可能是有用的。 –