4

I have a normal pre-populated database. I want to migrate it to core data for my app. What is the best way to achieve this. By the way I have done these things, copied the recipes.sqlite database from apple's sample.exported a table sql. Rename the column names according to the core data table columns(something like this - id "primary key" with Z_PK). filled that table with my values. But i am unable to understand the columns names Z_ENT and Z_OPT. Does some one knows how do i migrate my prepopulated sqlite3 database to core data easily.

Thanks

2 Answers 2

7

Do not try and manually create a Core Data SQLite file. That is a road to failure; every time.

If you have a pre-existing SQLite file then use straight SQLite tools to access it and import it into Core Data using Core Data. Once you have the data in a Core Data stack, save out that file and then use the resulting SQLite file.

The internal structure of the Core Data SQLite file is designed to be opaque and should not be reverse engineered. Apple makes no guarantee that the file structure will stay the same. They have changed it several times already since Core Data was released.

Import

To do the import, it would be just like any other file:

  1. You stand up the core data stack.
  2. You walk through each table and each row in the non-Core Data database.
  3. Create a new Core Data object for each row.
  4. Insert the data from the old row into the new object.
Sign up to request clarification or add additional context in comments.

7 Comments

could you please tell me the steps?
What about the Z_OPT column of core data?
You shouldn't care. The internals of the core data file are an implementation detail. Only use Core Data to touch the SQLite file.
I want to use prepopulated data. Also will i be able to use insert,update like we do in sqlite?
you can do anything that Core Data can do which includes, updating, inserting and deleting data. I suggest you learn a bit more about Core Data so that you can better understand what it is and how it functions.
|
1

Try the following tool which migrates the Standard SQLite to Core Data Compatible Sqlite

https://github.com/tapasya/Sqlite2CoreData

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.