Sam Fischer
Sam Fischer

Reputation: 1472

How to completely reset CoreData for an Xcode project?

My macOS application is a mess right now. I made some big changes to my Core Data model, and now, just launching the app causes the app and Xcode to crash. The app's crash log reveals the following reason for the crash:

Fatal error: Unresolved error Error Domain=NSCocoaErrorDomain Code=134140 "Persistent store migration failed, missing mapping model."

I don't want to create a mapping model. I don't care about the old CoreData model. I want all that data to go away. I have tried the following things:

  1. Deleting Derived Data.
  2. Deleting the ~/Library/Application Support/APP_NAME/ folder.
  3. Using NSBatchDeleteRequest to delete all the entities.

I want to start fresh (without creating a completely new project). What do I need to do to start all over again with a fresh Core Data dataset ?

Upvotes: 5

Views: 5452

Answers (3)

Droid Chris
Droid Chris

Reputation: 3773

Well if you are using the emulator, simply delete all data on it like so:

Select Simulator -> Device -> Erase All Content and Settings...

Click erase button

Upvotes: 2

Joe Bell
Joe Bell

Reputation: 13

Well, like @Willeke said, it seems to be as simple as finding the sqlite file and deleting it. That gets you a complete purge/reset without rebuilding the app. Still a pain though if you just want to tweak the structure a bit without losing the accumulated data. So for that scenario, maybe develop an export function first, dump the data, delete the sqlite file, then re-import the data.

Upvotes: 1

Willeke
Willeke

Reputation: 15589

Search in the Finder for yourAppName.sqlite. I found one in

~/Library/Containers/yourcompany.yourAppName/Data/Library/Application Support/yourAppName/

Upvotes: 8

Related Questions