Resolving CoreData error in iPhone Simulator

12 11 2009

I was working on an iPhone application in Xcode. It was the default CoreData table view application. When I tried to build and go, I got and error that told me the model used to access my database was incompatible with the model used to create it.

The error included this bit:

reason = “The model used to open the store is incompatible with the one used to create the store”;

Thanks to some quick, Google-powered research, I was able to find the answer. Every time that you make any data model changes to an iPhone application in development, you need to delete the application from the iPhone simulator or physical device before trying to build the application. When you delete an application on either platform, you delete all of the data associated with it, including the database that uses a now-obsolete data model, which causes Xcode to throw an error.

I am still a rookie software developer, and I have found that Google is not just for finding people with the same name as you. It can be a big help in finding resources and quick solutions. No matter what development issue that you may be having, chances are that someone else has already dealt with it and shared their experience.

Screen shot 2009-11-12 at 8.08.25 PM.png

Advertisements

Actions

Information

53 responses

20 04 2010
Leo

Thanks for the explanation..

26 04 2010
patrick42h

Not a problem. I am happy that someone was able to get some use out of this post. Cheers!

9 10 2010
aikhan

bravo

1 11 2010
Marc

I have run up against the same error but still not able to get past it. I have completely reset the simulator but still no luck.

I have been playing around with one of the code samples from Apple called ‘Recipes’ and was trying to add some additional columns to the database but as soon as I do, even before I begin to reference them in the code, I get this error!

14 03 2012
yunasqazi

Hmmmmm…. then you may try to insert the data of the same data type that you have defined in model.

14 12 2010
Zaldy B. N. Bughaw

Thanks Man, this saves me a lot of time and headache. 🙂

4 01 2011
Noomild

Thanks man !

8 01 2011
Jack

Thanks a lot for saving me lots of time…

13 01 2011
Mohammad Bahadur

Hey man, many thanks to you,
i was wasting my time till i found this.

27 01 2011
Kevin McCreary

Thanks. I knew it had to be out there. Just needed to google the exact phrase.

9 02 2011
Casper

It’s really a practical solution,
Thank you.

10 02 2011
patrick42h

Happy to help!

17 02 2011
Mark Robinson

Thanks, helped me

15 03 2011
Karida

Thanks, very much.
It’s easy to solve really if I know (but hard because I’m a noob).

16 03 2011
roderic campbell

Yes, but what if the app is in production already? How do you do a migration?

23 03 2011
Dor

Thanks for this! Really helped out!

2 04 2011
Joeyinbox

Huge thank’s!

12 05 2011
Van Du

Funny how your blog gave me the solution to this same problem.. lol

we’re looping

27 06 2011
Yasaswy Nagavolu

Thanks a bunch dude.. helped me to solve in a min.. yeah again google helped in redirecting here..

29 06 2011
thatzprem

Thanks for saving my time 🙂

10 07 2011
Maanas Royy

Thanx it saved me lot of time

12 07 2011
Denis

Thanks!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

22 07 2011
Igor

thanks 🙂

6 08 2011
Erwin

Thanks. Still useful after two years 🙂

13 08 2011
Arthur

Thanks man

20 08 2011
huotianjun

谢谢你

20 08 2011
Peer Boerner

I see I’m not the only one who ran into this. Many Thanks Indeed!!!!

20 10 2011
mobileman

Thanks!

27 10 2011
Ivan

thanks man thought it was my code.

26 11 2011
Erwan

2 years after and this still does the trick! Thanks man

6 12 2011
cora

i love you!

21 12 2011
Reuben

Thanks I was having this problem too!

26 12 2011
Sercan Karaoglu

Hi guys, you don’t need remove app. simply it is enough to only delete .sqlite file here below is the code to get this done

-(void)deleteAllNewsTypesFromDatabase{
NSError *error = nil;
NSURL *applicationDocumentsDirectory = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
NSURL *storeURL = [applicationDocumentsDirectory URLByAppendingPathComponent:@”Model.sqlite”];
[[NSFileManager defaultManager] removeItemAtPath:storeURL.path error:&error];
}

– (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self deleteAllNewsTypesFromDatabase];

28 12 2011
patrick42h

That is a much better solution. I would imagine it really saves some development time. Thanks for sharing!

2 01 2012
Brain2000

I’m thoroughly confused why there is so much praise here. If you are just going to delete the database file and make your customers start over, what is the purpose of versioning your model? This is so you can UPDATE the model structure, not so you can delete it and start over and tell your customer “sorry about your luck.” Or am I just missing the obvious?

2 01 2012
patrick42h

Frankly, I am still surprised that this post has received as much attention as it has. I wrote this about two years ago and I was still learning about iOS development. I still have not produced any production apps, so I was not too worried about deleting customer’s databases. My job takes so much of my time, I have not had much time to devote to iOS development. If you have a suggestion for how to update the model without deleting the database, feel free to post it here.

22 01 2012
Hendrik Ewert

Thank you for this quick and easy solution.
It saves a lot of time for coding.

Nice job, Hendrik

3 02 2012
csabaveres

Thanks. This is a quick way to fix the problem in early stages of development, which some of us need. No idea why some people are so envious that this post is so liked by some …

17 02 2012
sachith

saved my lot of time.

2 03 2012
alex

dude.. 3 years later ..you saved my evening ! thanks !

4 04 2012
es

you’ve been a great help!

10 04 2012
gebirgsbaerbel

so simple, when you think about it, but of course I did not by myself…
thank you 🙂

20 04 2012
Sindhu

Thank you so much……..it really helped me a lot…..

22 05 2012
boastabouttoast

Wow! I really have to thank you! I have spent hours modifying my database and deleting and recreating classes. I was about to give up, but decided to do a quick google search and I’m extremely glad I did! Worked like a charm! Easiest fix to any problem I’ve ever had, I couldn’t be any more grateful! Thank you!

13 06 2012
Naveen B

Wow! really thank you for your article.

26 06 2012
shyam parmar

i have the same problem but i didn’t use core data.

24 07 2012
nada magdy

Thanks alot , that solved the problem

4 08 2012
gagan g

thank you so much! spent over an hour trying to figure out what was wrong untill I found this.

30 10 2012
vivek

this really worked for me..
Thanks..

18 01 2013
Ricard

Muchas gracias!!!

6 02 2013
Leongiovanni

Thank you very much!

22 02 2013
Luma

Thank’s so much for the help. 🙂

9 05 2013
Miguel

Thank you soooo much!!!!!
I’m starting with native development in iOS and this was exactly what I needed, Thank you again Bro!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: