daveywc
daveywc

Reputation: 3146

Core Data Migration - Table Already Exists

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.

Upvotes: 7

Views: 2934

Answers (3)

Vladyslav Shmatok
Vladyslav Shmatok

Reputation: 434

I had a similar issue when I wanted to delete an entity from the new CoreData model version(SQLite error code:1, 'there is already another table or index with this name: Z_33TAGS'). There were no attribute or relationship tags in this entity, also when I tried to remove other similar entities everything worked fine. I managed to fix this removal by first adding a new version where I renamed this entity and then adding one more where I removed it.

Upvotes: 0

user1317655
user1317655

Reputation: 191

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.

Upvotes: 19

daveywc
daveywc

Reputation: 3146

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.

Upvotes: 5

Related Questions