Migrate normal sqlite3 database to core data?

2019-01-11 21:13发布

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条回答
疯言疯语
2楼-- · 2019-01-11 21:41

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.
查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-01-11 21:48

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

https://github.com/tapasya/Sqlite2CoreData

查看更多
登录 后发表回答