简体   繁体   中英

Updatating Core Data XCDATAMODEL entities causing Fatal error

I updated and added some fields of an existing Core Data entity. I didn't see any updating option so I don't know if what I did is correct.I updated some field type and added new fields in XCDATAMODEL, then I deleted the classes of this outdated version of entity (since I chose in XCDATAMODEL Manual under Codegen it generated code classes, to be honest I am not sure if it's doing it regardless of this choise) and then chose again in the Menu -> Editor - >Create NSMnagedObject Subclass after I did it for the first version of this entity.

This error appears right after activating the simulator:

Thread 1: Fatal error: Unresolved error Error Domain=NSCocoaErrorDomain Code=134140 "Persistent store migration failed, missing mapping model." UserInfo={destinationModel=(<NSManagedObjectModel: 0x60000249e170>) isEditable 0, entities {
OccupiedSpace = "(<NSEntityDescription: 0x60000308ce70>) name OccupiedSpace, managedObjectClassName OccupiedSpace, renamingIdentifier OccupiedSpace, isAbstract 0, superentity name (null), properties {\n    assignedTaskId = \"(<NSAttributeDescription: 0x60000298bb8

This is the entity class, I added month and year fields and changed the type of startTime from Date to Int32:

import Foundation
import CoreData


extension OccupiedSpace {

    @nonobjc public class func fetchRequest() -> NSFetchRequest<OccupiedSpace> {
        return NSFetchRequest<OccupiedSpace>(entityName: "OccupiedSpace")
    }


    @NSManaged public var startTime: Int32
    @NSManaged public var year: Int32
    @NSManaged public var month: Int32


}

when you update entity in core data, you need to do a migration

in case you update the entity in development only you can just delete the app in simulator/device first before running your project again

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM