简体   繁体   English

iOS-如何使用Core Data将2个实体迁移到1个实体?

[英]iOS - How to migrate 2 Entities into 1 using Core Data?

In my current model version I have this 4 Entities : 在我当前的模型版本中,我有以下4个实体:

  • Satellite (with relationship to one to SatelliteAnimation) 卫星(与卫星动画的关系)
  • SatelliteAnimation SatelliteAnimation

  • Radar (with relationship to one to RadarAnimation) 雷达(与RadarAnimation的关系)

  • RadarAnimation RadarAnimation

In my App I have different blocs in which I display information. 在我的应用程序中,我有不同的集团来显示信息。

This is why I have entities RadarAnimation and SatelliteAnimation , in order to recognize those blocs by type. 这就是为什么我有实体RadarAnimationSatelliteAnimation以便按类型识别这些块的原因。

Anyway, my issue is that I want to migrate 2 blocs in 1. And instead of having 4 Entities, I would like to have : 无论如何,我的问题是我想在1中迁移2个区块。我希望拥有4个实体,而不是:

  • Radar 雷达
  • Satellite 卫星
  • Animations 动画

I don't need the relationships anymore. 我不再需要这种关系了。

I know I can rename an Entity in a lightweight migration process. 我知道我可以在轻量级迁移过程中重命名实体。

What I would like to do is : 我想做的是:

  • Create a new data model version 创建一个新的数据模型版本
  • Delete the SatelliteAnimation entity 删除SatelliteAnimation实体
  • Delete the relationship between Satellite and SatelliteAnimation 删除Satellite和SatelliteAnimation之间的关系
  • Delete the relationship between Radar and RadarAnimation 删除Radar和RadarAnimation之间的关系
  • Rename the entity RadarAnimation by Animations 通过Animations重命名实体RadarAnimation
  • Set the new data model version as current model version 将新的数据模型版本设置为当前模型版本

Does this way of handling my issue will affect the migration process ? 这种处理我的问题的方式会影响迁移过程吗? Can I rename and remove relationships in a new data model version ? 我可以在新的数据模型版本中重命名和删除关系吗?

This should be possible with automatic lightweight migration. 自动轻量级迁移应该可以做到这一点。 Deleting entities and relationships just works with no extra steps, so that's fine. 删除实体和关系不需要任何额外步骤,所以很好。

To rename something you'll use the renaming identifier in the model editor. 要重命名,您将在模型编辑器中使用重命名标识符。 After you create the new version of your model, select the entity you want to rename in the model editor. 创建新版本的模型后,在模型编辑器中选择要重命名的实体。 Change its name but set the renaming identifier to the old name. 更改其名称,但将重命名标识符设置为旧名称。 In your case, change the entity name from RadarAnimation to Animation , but then also set the renaming identifier on the entity to RadarAnimation so Core Data knows what it used to be called. 在您的情况下,将实体名称从RadarAnimationAnimation ,然后还将实体上的重命名标识符设置为RadarAnimation以便Core Data知道它过去曾被调用过。

重命名标识符

Incidentally attributes and relationships can also have renaming identifiers, so they can also be renamed this way. 顺便说一下,属性和关系也可以具有重命名标识符,因此也可以通过这种方式重命名。

Apple provides detailed documentation on what can be done with lightweight migration which will probably be useful as you go through this. Apple提供了有关轻量级迁移可以完成的操作的详细文档,当您进行此操作时可能会很有用。

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

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