无需多个数据模型版本即可完成迁移.欢呼? [英] Migration can be done without multiple data model versions. Hurrah?

查看:76
本文介绍了无需多个数据模型版本即可完成迁移.欢呼?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我指的是一个很棒的教程 Swift核心数据迁移核心数据的教程.

I was referring a wonderful tutorial Swift Core Data Tutorial for migrations in core data.

该研究报告指出,核心数据中的迁移与多种版本的数据模型齐头并进.

The tut stated that migrations in core data go hand in hand with multiple versions of data model.

我正在尝试进行轻量级迁移,并弄清了以下几点:

I was experimenting on light-weight migrations and got to figure out the following points:

场景-我有一个数据模型,尝试向实体添加一些新属性,但出现错误--

Scenario - I had a data model and I tried to add a some new attributes to an entity and I got an error as -

iOS版本-9.1 Swift版本-2.2

iOS Version - 9.1 Swift Version - 2.2

"用于开设商店的模型与以前用来兼容商店的模型不兼容 创建商店"

"The model used to open the store is incompatible with the one used to create the store"

然后我 试图通过添加代码-

I then tried to enable migration without creating any new version by adding the code -

let options = [ NSMigratePersistentStoresAutomaticallyOption : true, NSInferMappingModelAutomaticallyOption : true ]

try persistentStoreCoordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: URLPersistentStore, options: options)

然后我尝试类似地更改数据库,即向实体添加属性并欢呼!!,这没有导致崩溃.甚至我都尝试访问特定实体以及属性,但都成功完成了.

Then I tried altering the database similarly, i.e added an attribute to an entity and hurrah !!, it didn't result in a crash. Even I tried to access the particular entity as well as attribute but did it successfully.

发生的事情是没有多个版本的迁移.

What happened is migration without having multiple versions.

问题- 那么在没有多个版本的数据模型的情况下可以迁移吗?

Question - So Is migration possible without having multiple versions of data model?

链接到示例代码- https://www.dropbox.com/s/mnb2dzxn56ghuet/CoreDataSwift-NSFetchedResultsController-master-2.zip?dl=0

推荐答案

从iOS 9开始,Core Data会将数据模型复制到持久性存储中,并以轻量级为起点迁移是必需的,也是必需的.结果,即使旧模型版本不可用,也可以进行轻量级迁移.这仅适用于SQLite持久存储,并且仅适用于轻量级模型迁移.

Beginning with iOS 9, Core Data will copy the data model to the persistent store, and use that as the starting point if lightweight migration is necessary and requested. As a result, lightweight migration is possible even if the old model version is not available. This only works with SQLite persistent stores, and only for lightweight model migrations.

在WWDC上的核心数据会话中的新增内容中对此进行了描述2015.

This was described in the What's New in Core Data session at WWDC 2015.

这篇关于无需多个数据模型版本即可完成迁移.欢呼?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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