简体   繁体   English

我是否需要进行大量迁移以修改核心数据中的关系?

[英]Do I need to do a heavy migration to modify relationships in core data?

My app loads user info from my backend and then attempts to save everything using core data. 我的应用程序从后端加载用户信息,然后尝试使用核心数据保存所有内容。 I have a couple of entities, and some one to many relationships in my data model. 我的数据模型中有几个实体以及一对多关系。 My question is, if the data changes in my database, and I need to modify the relationships between entities, for example add/delete, do I need to do a heavy migration? 我的问题是,如果数据库中的数据发生了变化,并且我需要修改实体之间的关系(例如添加/删除),是否需要进行大量迁移? I have searched and read a lot online, it seems like lightweight migration is not gonna do it because I'm not manually adding attributes/entities. 我在网上搜索和阅读了大量内容,似乎轻量级迁移无法做到,因为我没有手动添加属性/实体。 And if I do need to do a heavy migration, how would one go about that? 如果我确实需要进行大量迁移,那该怎么办? There is really not too much I could find about heavy migration out there. 关于那里的大量迁移,我真的发现不了太多。

I also thought of just deleting previous data models every time I make a change then save the entire new entity. 我还想到了每次更改时都只删除以前的数据模型,然后保存整个新实体。 I'm not so sure if that is a good approach, is there a better way to cache/store data that's retrieved from backend? 我不确定这是否是一种好方法,是否有更好的方法来缓存/存储从后端检索到的数据?

If you are not changing the model you need no migration. 如果你不改变你的模型不需要迁移。

That is, "migration" in the sense that Apple uses it, ie only in reference to the data model . 也就是说,“迁移”在Apple使用它的意义上,即仅参考数据模型 What you mean is perhaps a data "update". 您的意思可能是数据“更新”。

You do data updates in the usual way: fetch the objects you want to modify, change them (eg, set different objects as relationships), save. 您可以按照通常的方式进行数据更新:获取要修改的对象,进行更改(例如,将不同的对象设置为关系),保存。

Probably you have done this but in case you haven't, when you change the model you need to save as a new version then select that one as current version with that the error should go away. 可能您已经这样做了,但是如果您没有这样做,那么当您更改模型时,需要将其另存为新版本,然后选择该版本作为当前版本,这样错误就会消失。

Here are the steps: 步骤如下:

  1. Select Model.xcdatamodeld. 选择Model.xcdatamodeld。
  2. Click Editor > Add Model Version.... 单击编辑器>添加模型版本...。
  3. Click Finish to accept Model 2 as the version name. 单击完成以接受Model 2作为版本名称。
  4. Select Model.xcdatamodeld. 选择Model.xcdatamodeld。
  5. Click View > Utilities > Show File Inspector (or press Option+⌘+1). 单击查看>实用程序>显示文件检查器(或按Option +⌘+ 1)。
  6. Set the Current Model Version to Model 2. 将当前模型版本设置为模型2。

Here a link with explains this process: Learning CoreData for iOS: Managed Object Model Migration 此处的链接说明了此过程: 学习iOS的CoreData:托管对象模型迁移

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

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