通过迁移将Core Data Index添加到某些属性 [英] Add Core Data Index to certain Attributes via migration

查看:185
本文介绍了通过迁移将Core Data Index添加到某些属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于性能原因,我要为我的一些实体设置索引属性。我创建了一个新的核心数据模型版本来执行更改。 Core Data检测更改并将我的模型迁移到新版本,但未生成INDEXES

For performance reasons, i want to set the Indexed Attribute to some of my entities. I created a new core data model version to perform the changes. Core Data detects the changes and migrates my model to the new version, however, NO INDEXES ARE GENERATED.

如果我从头重新创建数据库,索引就在那里。
我在SQLite浏览器在iPhone和模拟器检查。
只有在以前格式的数据库已经存在的情况下才会出现这个问题。

If I recreate the database from scratch, the indexes are there. I checked with SQLite Browser both on the iPhone and on the Simulator. The problem only occurs if a database in the prior format is already there.

有没有办法手动添加索引?写一些sql的?还是我错过了什么?我已经有一些更关键的迁移,没有问题。

Is there a way to manually add the indexes? Write some sql for that? Or am I missing something? I did already some more critical migrations, no problems there. But those missing indexes are bugging me.

推荐答案

p>我有同样的问题。

I had the same problem.

根据核心数据模型版本化和数据迁移编程指南


Core Data对版本控制的看法
是它只对模型的
特性感兴趣,影响
持久性。

Core Data’s perspective on versioning is that it is only interested in features of the model that affect persistence.

只要向现有模型属性添加索引,就不会自动触发迁移,因为Core Data不会将您的两个模式模式看作不同(索引不会影响持久性)。

Simply adding an index to an existing model property does not automatically trigger a migration since Core Data does not see your two model schemas as being different (an index does not affect persistence).

但是,您可以通过向新索引的属性添加Version Hash修饰符,使Core Data看到您的模型被更改。这会触发轻量级迁移以更新现有的数据库。

You can, however, cause Core Data to see your model as being changed by adding a Version Hash Modifier to your newly indexed attribute. This triggered lightweight migration to update my existing databases.

这篇关于通过迁移将Core Data Index添加到某些属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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