我想在我的项目中添加一个新的核心数据实体。我是否需要为此添加新的核心数据模型版本,否则它将在现有版本中工作?该实体是独立的,它将与其他先前定义的实体没有任何关系。
确实,它需要添加一个新的模型版本。但是,添加新实体可以由 lightweight migration 处理。 ,因此至少您不必创建映射模型/编写自定义迁移代码。
更新:
来自关于轻量级迁移的文章:
In addition, Core Data supports: ... Changing the entity hierarchy
- You can add, remove, rename entities
- You can create a new parent or child entity and move properties up and down the entity hierarchy
- You can move entities out of a hierarchy
- You cannot, however, merge entity hierarchies; if two existing entities do not share a common parent in the source, they cannot share a common parent in the destination
如果你不使用版本控制,你会得到这样的错误:
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"; }
这对我来说似乎是使用版本控制的好理由)
关于ios - 在 Core Data 中添加新的独立实体是否需要模型版本控制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36261757/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |