在Core Data中添加新的独立实体是否需要模型版本控制? [英] Does adding a new independent entity in Core Data require model versioning?

查看:27
本文介绍了在Core Data中添加新的独立实体是否需要模型版本控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的项目中添加一个新的核心数据实体.我是否需要为此添加新的核心数据模型版本,或者它可以在现有版本中使用?该实体是独立的,并且将与其他先前定义的实体没有任何关系.

I want to add a new Core Data Entity in my project. Do I need to add a new core-data Model Version for this or it will work within existing version? The entity is independent and it will have no relation with other previously defined entities.

推荐答案

实际上,它需要添加新的模型版本.但是,添加新实体可以通过轻量级迁移,因此至少您不必创建映射模型/编写自定义迁移代码.

Indeed, it requires adding a new model version. However, adding a new entity can be handled by a lightweight migration, so at least you don't have to create a mapping model/write custom migration code.

更新:

摘自有关轻量级迁移的文章:

From the article about lightweight migration:

此外,Core Data支持:...更改实体层次结构

In addition, Core Data supports: ... Changing the entity hierarchy

  • 您可以添加,删除,重命名实体
  • 您可以创建一个新的父实体或子实体,并在实体层次结构中上下移动属性
  • 您可以将实体移出层次结构
  • 但是,您不能合并实体层次结构;如果两个现有实体在源中不共享同一父代,则它们不能在目的地有一个共同的父母

如果您不使用版本控制,则会收到如下错误:

And if you don't use versioning, you'll get an error like this:

错误域= NSCocoaErrorDomain代码= 134100(空)"UserInfo = {元数据= {NSPersistenceFrameworkVersion = 641;NSStoreModelVersionHashes = {TestEntity1 =;};NSStoreModelVersionHashesVersion = 3;NSStoreModelVersionIdentifiers =(");NSStoreType = SQLite;NSStoreUUID ="F16AD345-02FE-4E94-B11E-3BC337B16568";"_NSAutoVacuumLevel" = 2;},reason =用于开设商店的模型与用于创建商店的模型不兼容},其中userInfo字典{元数据= {NSPersistenceFrameworkVersion = 641;NSStoreModelVersionHashes = {TestEntity1 =;};NSStoreModelVersionHashesVersion = 3;NSStoreModelVersionIdentifiers =(");NSStoreType = SQLite;NSStoreUUID ="F16AD345-02FE-4E94-B11E-3BC337B16568";"_NSAutoVacuumLevel" = 2;};原因=用于开设商店的模型与用于创建商店的模型不兼容";}

Error Domain=NSCocoaErrorDomain Code=134100 "(null)" UserInfo={metadata={ NSPersistenceFrameworkVersion = 641; NSStoreModelVersionHashes = { TestEntity1 = ; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers = ( "" ); NSStoreType = SQLite; NSStoreUUID = "F16AD345-02FE-4E94-B11E-3BC337B16568"; "_NSAutoVacuumLevel" = 2; }, reason=The model used to open the store is incompatible with the one used to create the store} with userInfo dictionary { metadata = { NSPersistenceFrameworkVersion = 641; NSStoreModelVersionHashes = { TestEntity1 = ; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers = ( "" ); NSStoreType = SQLite; NSStoreUUID = "F16AD345-02FE-4E94-B11E-3BC337B16568"; "_NSAutoVacuumLevel" = 2; }; reason = "The model used to open the store is incompatible with the one used to create the store"; }

这似乎是对我使用版本控制的一个很好的理由)

This looks like a good reason to use versioning to me)

这篇关于在Core Data中添加新的独立实体是否需要模型版本控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆