I have an existing iPad application to which I've just added core data versioning. I've been through the documentation and followed the steps detailed. Now after choosing my new model as the current versioned model and trying to run it on my dev device from xCode I get the following error:
2012-03-28 07:35:42.137 DocsOnTap[2603:707] CoreData: error: (1) I/O error for database at /var/mobile/Applications/06EECF01-3598-4513-8A3A-BE4FD49EEBF6/Documents/.DocsOnTap.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3. SQLite error code:1, 'table Z_2TAG already exists'
The only change that I made to my model was to add in a single new entity. I have a table named Tag in my model - that appears to be what the error is referring to.
If I revert my current versioned model back to the previous model version then I can run my app on my dev device from Xcode without error.
I have read that there can be problems trying to use core data migration on dev devices. However I just want to test the process to be sure that when we update our app in the Appstore the migration works as expected for our customers.
In my case the same error appeared due to Renaming ID which was set in the Data Model inspector for the Entity. After I removed the Renaming ID the problem'd gone.
Well this was an obscure error. The entity that I was adding was named AppKeys - this must be the name of an entity used internally by core data or SQL Lite. I went back to scratch and found that I could add and migrate other attributes and entities without any problems. However if I tried once again to add my entity named AppKeys then I got the same error saying that 'table Z_2TAG already exists'. So the resolution to my problem is to choose another entity name. It is a pity that this is not documented somewhere obvious - or that the error was not more helpful. Anyway hopefully this might just help someone else one day.
Related
I am working on a iOS mobile application using Xcode as the IDE and Swift as the language of choice. I added a column to the SQLite database that interacts with my application but unfortunately when I attempt to perform any database operations through the application the column is not recognized.
The following error is sent:
DB Error: 1 "table xyz has no column named column_name"
When I added the column I also increased the database version or user_version in SQLiteStudio.
Is there something else I should be doing to cause the application to recognize the changes? I know uninstalling and reinstalling would work but that is not an option of course as I cannot lose the data currently housed in the database. My other idea was to put all the data in temporary variables or something like that, drop and recreate the tables and reinsert the data. I wasn't sure if this was a good course of action though. Any help with this is appreciated.
If I add a new model version and then add an attribute to an entity I get a migration failure. It doesn't matter what the type of the attribute is or whether it is optional or has a default value. If I just add the new model version but don't add the attribute it works OK. I have done this sort of thing lots of times over the past 3 years without problems. Both NSMigratePersistentStoresAutomaticallyOption and NSInferMappingModelAutomaticallyOption are set to true. The error I get is shown below.
2018-02-18 12:28:51.771608+0000 Writing Shed[4105:1886727] [error] error: Illegal attempt to save to a file that was never opened. "This NSPersistentStoreCoordinator has no persistent stores (schema mismatch or migration failure). It cannot perform a save operation.". Last recorded error = Error Domain=NSCocoaErrorDomain Code=134140 "Persistent store migration failed, missing mapping model."
Does anyone know what might be wrong?
I've found the problem. I'm developing an app on Mac OS that is already available on IOS. They sync CoreData via iCloud. At some point while working on the Mac I added some attributes to the model that weren't optional or defaulted. To cut a long story short this caused problems with an IOS store that predated the changes, so that's when the migration failed (can't migrate to non-optional/non-defaulted attributes). I'm still not sure how I got into this situation because I'm usually very careful with CoreData, but hey stuff happens. Thanks for the comments which made me look deeper.
I'm running into a frequent MVC DB first issue where everytime I update my domain model classes from the DB, something always seems to be breaking. In this case, after adding another table and model into my project, running Update model From Database and Generate Model From DB in the .EDMX file, a perfectly good table with a working query is causing the Invalid Object Name error when the app runs in the browser.
I've cleaned and rebuilt my project multiple times. Everything compiles and the error only occurs when the app tries to run in the browser.
Is DB First prone to being buggy or am I not doing something properly when using DB first approach?
Error Screens
At the early stages of development, where data retention is no issue and experimental changes to the schema are expected to be numerous, is there a way to avoid migration? Namely, just to dump the database and start over each time.
Everything I try leads to the error: "The model used to open the store is incompatible with the one used to create the store".
Lightweight migration looks do-able, but I'll end up lots of unwanted versions and messy code. I'd also like to experiment with relationships (no wise cracks), but understand I'd need to commit to a heavyweight migration afterwards!
If the solution is to check for the existence of the original database using NSFileManager and delete/remove it if found, could someone please show the swift code with an example name of the original database, and how it can be effectively removed.
I've been trying several suggested solutions, such as dragging a copy of the .xcdatamodeld file onto the desktop, deleting the file in xcode and bringing it back in, but I keep getting the error that the model and store are not the same.
Answered in one line in first comment, but appreciated in reverse proportion.
I received the source for an application from a guy to make a few changes in the app. The data model version was, say, App3. I had to add about 3-4 more data model versions in the process. So the active model version when I sent him was App7
I built the project (it was running properly on my mac)
I sent him the zip and when he ran, he got the error "Can't find model for source store"
I had him create the latest data model again, based on the data model App3 and make it the same as App7 and set it as the current version.
He still has the error and I can't figure out why? Are the intermediate data model version causing issues? Is it required to delete the sqlite file in the application support->iphone simulator folder? I am all over the place with this. Please help!
You need to have both model files and have some sort of versioning in place. The new model that you made will no longer work with his data file unless you specify to Core Data that you want it to update the data.
Versioning isn't that easy, but if your changes are small enough, you might be able to get away with automatic versioning. Read the guide and see:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/Introduction.html
In my understanding, it will. But really that is not the thing to do if ultimately the versioning is going to happen on existing live apps too.
For the light-weight migration to work, you need to send him all the intermediate versions of the model as well since the migration takes place stage by stage through all versions.
And you have to make sure that you have made no modification (even accidentally) to the base version App3.