简体   繁体   English

代码 = 134110 - 验证错误缺少强制性目标属性上的属性值

[英]Code=134110 - Validation error missing attribute values on mandatory destination attribute

Context:语境:

  • app using CoreData使用 CoreData 的应用程序
  • some lightweight migration successfully performed in the past (reached the 4th iteration of the model version)过去成功执行了一些轻量级迁移(达到模型版本的第 4 次迭代)
  • client wants a new feature客户想要一个新功能
    • created a 5th model version创建了第 5 个模型版本
    • added one single lousy new property, a non-optional boolean called new_one, to the TestModel entity向 TestModel 实体添加了一个糟糕的新属性,一个名为 new_one 的非可选布尔值

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无论是正确的做法还是普通的 hack ......我不知道......但它解决了我的问题,我现在可以继续下一个

在此处输入图片说明

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.迁移后,每个迁移的对象都具有您在迁移期间提供的任何值。

I think providing a default value is better than superfluous optionality.我认为提供默认值比多余的可选性更好。

在此处输入图片说明

Better to use optional only when a value is indeed optional.仅当值确实是可选的时才使用 optional 更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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