3

My app is crashing when ever i change the data model. Inorder to run it again i should delete the app from simulator and the run it. Instead of doing this is there any means that we can run the app without deleting whenever we change the datamodel. i want the previous data to be used. Thanks in advance

Vijay
  • 420
  • 6
  • 18
  • Unresolved error Error Domain=NSCocoaErrorDomain Code=134130 "The operation couldn’t be completed. (Cocoa error 134130.)" UserInfo=0x5f56690 {URL=/Users/vijaymunduru/Library/Application Support/iPhone Simulator/4.2/Applications/F553817C-C759-4885-A00A-544BE2A930E6/Documents/vijay.sqlite, metadata={type = immutable dict, count = 7, this the crash report – Vijay Aug 23 '11 at 04:27
  • Based on your error code, check here for more info: http://stackoverflow.com/questions/3146515/iphone-core-data-lightweight-migration-cocoa-error-134130-cant-find-model-for-s – coneybeare Aug 23 '11 at 12:25

4 Answers4

4

The answer is a bit tricky but this always works for me. This is for a clean installation of a new compatible .sqlite file, not a migration!

launch simulator, delete the app and the data (the popup after you delete the app).

quit simulator

open X-Code, after making any edits to your data model

if needed update the datamodel version:

  1. Editor > Add Model Version...
  2. set your prefs in the dialog that appears (counting up is preferable)
  3. click on the {appname}.xcdatamodeld then in the far right pane
  4. click the left icon of the 3 icons on top of the far right column
  5. under Versioned Core Data Model select the one you just created

delete the {*appname*}.sqlite file (or back it up, remove it from project folder, and delete reference)

clean the app (Product > Clean)

Run the app in a simulator (for this tutorial I will assume 4.2)

While the simulator is running, in a Finder window, navigate to: {*home*} > Library > Application Support > iPhone Simulator > 4.2 > Applications > {*random identifier*} > Documents > {*appname*}.sqlite

Copy this file to another location

Stop running your app in X-Code

Drag and drop the {appname}.sqlite file into the files list in X-Code.

In the dialog that pops up, make sure the copy to folder checkbox, is checked.

Product > Clean

Then run the app in the simulator again

Now you should have a working sqlite file!

Cheers, Robert

roberthuttinger
  • 1,172
  • 1
  • 17
  • 31
3

Basically you need to be able to migrate existing data to the new schema -- read up on Core Data Versioning and Data Migration.

Chaitanya Gupta
  • 4,043
  • 2
  • 31
  • 41
  • I used LightweightMigration still it is getting crashed. any ideas? – Vijay Aug 23 '11 at 04:15
  • Unresolved error Error Domain=NSCocoaErrorDomain Code=134130 "The operation couldn’t be completed. (Cocoa error 134130.)" UserInfo=0x5f56690 {URL=/Users/vijaymunduru/Library/Application Support/iPhone Simulator/4.2/Applications/F553817C-C759-4885-A00A-544BE2A930E6/Documents/vijay.sqlite, metadata={type = immutable dict, count = 7, this is the error i am getting. Please help me in this regard – Vijay Aug 23 '11 at 04:27
  • I think you should do what @pokstad is suggesting. – Chaitanya Gupta Aug 23 '11 at 04:35
  • Link is not working - "Sorry, that page cannot be found" – Aviram Netanel Feb 01 '16 at 14:33
1

The file being used for NSPersistentStore can only correspond to one version of a Data Model at a time. You need to either do a migration of the data to the new version or tell your application to delete the persistent store file each time you start (for development purposes only).

Just saw that you want to keep your old data. You can try serializing your data to a NSDictionary and then saving it to a plist/json/xml file. Then, when your program starts you can delete the old NSPersistantStore file and create a new one. Import the data from the plist/json/xml file to the new empty persistent store file.

Remember, in order for light migration to work you need to keep the previous version of the data model in addition to the new one. Core data needs to know both models, past and present, in order to perform a migration.

pokstad
  • 3,411
  • 3
  • 30
  • 39
  • Yup. I am using lightweightmigration still i couldn't able to stop the app to crash. Can you elaborate like what the process that we should go while we change the data model. – Vijay Aug 23 '11 at 04:16
  • Try doing manual migration. You can serialize your data and save it to a plist file and then reimport it. It can be a lot of work depending on the size of your data model, but it's great for big changes to the data model that you can't use light migration for. – pokstad Aug 23 '11 at 04:19
  • Unresolved error Error Domain=NSCocoaErrorDomain Code=134130 "The operation couldn’t be completed. (Cocoa error 134130.)" UserInfo=0x5f56690 {URL=/Users/vijaymunduru/Library/Application Support/iPhone Simulator/4.2/Applications/F553817C-C759-4885-A00A-544BE2A930E6/Documents/vijay.sqlite, metadata={type = immutable dict, count = 7, This is the error i am getting. Can you help me in this regard – Vijay Aug 23 '11 at 04:26
  • This guy had the same error: http://stackoverflow.com/questions/1830079/iphone-core-data-automatic-lightweight-migration – pokstad Aug 23 '11 at 04:29
  • I used Light Weight Migration. when ever I add a field to entity the the app is not crashing. but when i delete a field then the app gets crashed. – Vijay Aug 23 '11 at 04:33
  • Are you creating a new version of your data model instead of replacing the old one? There should be a new version of your data model every time you make a change. Refer to the link I posted above. – pokstad Aug 23 '11 at 04:35
0

I have the same problem and I haven't fixed it yet. I don't care yet. While my app is in development I just clear the data every time I change the model.

I think to use Lightweight Migration, you still have to make a copy of your data model for every version of the data model you want to migrate from or to. It's lightweight, but not lightweight enough for when you're changing your data model frequently in early development.

I suggest you catch the exception it throws when it can't load the data, and have your program automatically delete the data in that case and recreate it in an initial state. It's the same as the ignore the problem answer but you don't have to manually delete the data every time. You probably ought to leave that code in for production, as a backup in case migration doesn't work for some reason, but maybe you ought to ask the user if they want to delete the data.

morningstar
  • 8,952
  • 6
  • 31
  • 42