通过迁移将核心数据索引添加到某些属性
出于性能原因,我想为我的一些实体设置索引属性。我创建了一个新的核心数据模型版本来执行更改。 Core Data 检测到更改并将我的模型迁移到新版本,但是未生成任何索引。
如果我从头开始重新创建数据库,索引就在那里。 我在 iPhone 和模拟器上使用 SQLite 浏览器进行了检查。 仅当先前格式的数据库已存在时才会出现此问题。
有没有办法手动添加索引?为此写一些sql?或者我错过了什么?我已经做了一些更关键的迁移,没有任何问题。但那些缺失的索引困扰着我。
感谢您的帮助!
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.
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.
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.
Thanks for helping!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我也有同样的问题。
根据核心数据模型版本控制和数据迁移编程指南:
简单地将索引添加到现有模型属性不会自动触发迁移,因为 Core Data 不会将您的两个模型模式视为不同(索引不会影响持久性)。
但是,您可以通过向新索引的属性添加版本哈希修饰符,使 Core Data 将您的模型视为已更改。这触发了轻量级迁移以更新我现有的数据库。
I had the same problem.
According to the Core Data Model Versioning and Data Migration Programming Guide:
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).
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.
您使用了什么迁移策略?
在 XCode 中,您可以生成映射模型,并查看将发生的更改,包括索引。
我建议简单地添加映射模型,验证指定的索引更改,然后执行自动轻量级迁移:
持久存储协调器将自动发现映射模型,并使用它来执行迁移。听起来运行时推断模型对将索引应用于实体属性并不敏感。
What migration strategy did you use?
In XCode you can generate a mapping model, and view the changes that will occur, including indexing.
I suggest simply adding the mapping model, verifying the index changes are specified, and do the automatic lightweight migration:
The Persistent store coordinator will auto-discover the mapping model, and use it to perform the migration. It sounds like the run-time inferred model is not sensitive to applying indexes to entity properties.