Code=134110 - Validation error missing attribute values on mandatory destination attribute
Asked Answered
E

2

17

Context:

  • app using CoreData
  • some lightweight migration successfully performed in the past (reached the 4th iteration of the model version)
  • client wants a new feature
    • created a 5th model version
    • added one single lousy new property, a non-optional boolean called new_one, to the TestModel entity

The outcome:

CoreData: error: NSUnderlyingError = "Error Domain=NSCocoaErrorDomain Code=134110 \"An error occurred during persistent store migration.\" 

UserInfo={

entity= TestModel, 

attribute=new_one, 

reason=Validation error missing attribute values on mandatory destination attribute}";

}

Solution:

I don't completely grasp why this happens (I'm too tired and eager to leave this problem behind), but the "mandatory destination attribute" thing pointed me in the direction of setting the property as an optional. Whether it's the right thing to do or just an ordinary hack...I don't know...but it solved my problem, I can now move on to the next

enter image description here

Ephod answered 7/9, 2017 at 9:17 Comment(0)
S
28

You've pretty much hit the nail on the head but it sounds like maybe you don't know why. It's because:

  1. The attribute was required
  2. Which means it must have a value when changes are saved
  3. Migration saves changes, but
  4. You didn't provide any value for this attribute.

That leads directly to the error that you received.

You can fix this using any one of the following:

  • Make the attribute optional, as you did. After migration, no migrated objects have a value, but that's OK.
  • Keep it non-optional but provide a default value in the model editor. After migration, all migrated objects have the default value.
  • Set up a non-lightweight migration and provide values when migration occurs. After migration, each migrated object has whatever value you provide during migration.
Sheridan answered 7/9, 2017 at 21:12 Comment(1)
I have a question to your third fix suggestion. Should I set a default value or optional for the new attribute in the model editor in this case? I use CoreData with heavyweight migration in my project. Migration models and MigrationPolicy are implemented so everything works fine BUT sometimes CoreData fails after the NSPersistentContainer.loadPersistentStores call with Code=134110 and UserInfo={entity=MyEntity, attribute=myNewAttribute, reason=Validation error missing attribute values on mandatory destination attribute}. This happens right after a successful migration.Georgeta
C
2

I think providing a default value is better than superfluous optionality.

enter image description here

Better to use optional only when a value is indeed optional.

Columbium answered 19/11, 2020 at 14:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.