3
votes

This is what I have in source model for Business entity:

enter image description here

and this is what I have in destnation model for Business entity:

enter image description here

As you can see I changed relationship from many to one, from users to user.

But now I have the following error:

URL:file:///private/var/mobile/Containers/Shared/AppGroup/00C2A6C6-8149-4CF7-95E1-6ABD8A2B3B57/POSowner.sqlite options:{
    NSInferMappingModelAutomaticallyOption = 1;
    NSMigratePersistentStoresAutomaticallyOption = 1;
} ... returned error Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." UserInfo={sourceURL=file:///private/var/mobile/Containers/Shared/AppGroup/00C2A6C6-8149-4CF7-95E1-6ABD8A2B3B57/POSowner.sqlite, reason=Cannot migrate store in-place: Validation error missing attribute values on mandatory destination relationship, destinationURL=file:///private/var/mobile/Containers/Shared/AppGroup/00C2A6C6-8149-4CF7-95E1-6ABD8A2B3B57/.POSowner.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3, NSUnderlyingError=0x170458990 {Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." UserInfo={entity=Business, attribute=user, reason=Validation error missing attribute values on mandatory destination relationship}}} with userInfo dictionary {
    NSUnderlyingError = "Error Domain=NSCocoaErrorDomain Code=134110 \"An error occurred during persistent store migration.\" UserInfo={entity=Business, attribute=user, reason=Validation error missing attribute values on mandatory destination relationship}";
    destinationURL = "file:///private/var/mobile/Containers/Shared/AppGroup/00C2A6C6-8149-4CF7-95E1-6ABD8A2B3B57/.POSowner.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3";
    reason = "Cannot migrate store in-place: Validation error missing attribute values on mandatory destination relationship";
    sourceURL = "file:///private/var/mobile/Containers/Shared/AppGroup/00C2A6C6-8149-4CF7-95E1-6ABD8A2B3B57/POSowner.sqlite";
}
fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." UserInfo={sourceURL=file:///private/var/mobile/Containers/Shared/AppGroup/00C2A6C6-8149-4CF7-95E1-6ABD8A2B3B57/POSowner.sqlite, reason=Cannot migrate store in-place: Validation error missing attribute values on mandatory destination relationship, destinationURL=file:///private/var/mobile/Containers/Shared/AppGroup/00C2A6C6-8149-4CF7-95E1-6ABD8A2B3B57/.POSowner.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3, NSUnderlyingError=0x170458990 {Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." UserInfo={entity=Business, attribute=user, reason=Validation error missing attribute values on mandatory destination relationship}}}: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-800.0.58.6/src/swift/stdlib/public/core/ErrorType.swift, line 178
2016-11-30 14:25:43.070185 POSowner[3474:513840] fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." UserInfo={sourceURL=file:///private/var/mobile/Containers/Shared/AppGroup/00C2A6C6-8149-4CF7-95E1-6ABD8A2B3B57/POSowner.sqlite, reason=Cannot migrate store in-place: Validation error missing attribute values on mandatory destination relationship, destinationURL=file:///private/var/mobile/Containers/Shared/AppGroup/00C2A6C6-8149-4CF7-95E1-6ABD8A2B3B57/.POSowner.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3, NSUnderlyingError=0x170458990 {Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." UserInfo={entity=Business, attribute=user, reason=Validation error missing attribute values on mandatory destination relationship}}}: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-800.0.58.6/src/swift/stdlib/public/core/ErrorType.swift, line 178

and I do not know what to do to workaround that issue. Any ideas?

This is how I setup core data stack:

static func mr_setupCoreDataStack() {

    guard NSPersistentStoreCoordinator.mr_default() == nil else {
        return
    }

    let managedObjectModel = NSManagedObjectModel.mr_default()
    let persistentStoreCoordinator = NSPersistentStoreCoordinator(managedObjectModel: managedObjectModel!)

    var storePath = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: SharedGroupName)
    storePath = storePath!.appendingPathComponent("POSowner.sqlite")

    let options = [NSMigratePersistentStoresAutomaticallyOption: true, NSInferMappingModelAutomaticallyOption: true]

    try! persistentStoreCoordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: storePath, options: options)

    NSPersistentStoreCoordinator.mr_setDefaultStoreCoordinator(persistentStoreCoordinator)
    NSManagedObjectContext.mr_initializeDefaultContext(with: persistentStoreCoordinator)
}
1

1 Answers

0
votes

The simplest solution is to remove current database and allow MagicalRecord create a new one without any migrations. Remember to do it only ONCE.

static func mr_setupCoreDataStack() {

    var storePath = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: SharedGroupName)
    storePath = storePath!.appendingPathComponent("POSowner.sqlite")
    try! FileManager.default.removeItem(at: storePath!)

}