Our app got released in app store and now I wanted work on next version. Here I might add property and entity to current model .
I am using core data with Magical record .
I need help on core data migration with magical record .
I am already using [MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:@"xxxxxxx"]; in app delegate .
As per my understand MR will take care of migration if we use above method .
Should I need to do any changes in Model.xcdatamodeld like adding model version (Editor->Add model Version) .
Please help me how can migrate core data.
To build on @casademora answer who obviously knows a lot more about MR than me, here is what got stuff working for me. The key is reading the Apple docs as suggested.
highlight your existing .xcdatamodel and then click Editor > Add model version > name it with an increment from your previous (i.e. if "myapp" use "myapp 2" as suggested in xcode.
make your changes on the newly created .xcdatamodel.
highlight the parent .xcdatamodel and then on the File Inspector on the right of xcode select your new version as the current Model Version.
NOTE: This step is only required if doing more than a Lightweight Migration. Select File > New > File > Core Data > Mapping Model. Choose your original as source, new as target and then save in the same folder as your .xcdatamodel.
make sure you are using setupAutoMigratingCoreDataStack or setupCoreDataStackWithAutoMigratingSqliteStoreNamed of course
test by downloading the app from app store and opening it, then closing and running debug over the top. You should not get any "Removed incompatible model version" messages (i.e. all persistent data should be in place still) or any other errors.
That method simply enables auto migrations to happen when you have multiple versions of a data model in your application bundle. To add a new version of a data model, you'll need to select your data model in Xcode, and in the menu select Editor -> Add Model Version... From there, Xcode will do the proper setup for you. This is also a fairly simple idea, it creates a new data model file, that starts off as the contents of your current data model file. From there, you can change and edit your data model as you see fit. Be aware that only simple changes are "automatic". Adding a new property is valid if it has a default value. Adding a new entity falls into the automatic category as well. I suggest reading more details about Core Data Migrations from Apple's Official Documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With