Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add Core Data Index to certain Attributes via migration

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!

like image 517
steipete Avatar asked Feb 01 '10 17:02

steipete


1 Answers

I had the same problem.

According to the Core Data Model Versioning and Data Migration Programming Guide:

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

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.

like image 193
Scott McCammon Avatar answered Nov 18 '22 15:11

Scott McCammon