Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6207829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:42:06+00:00 2026-05-24T05:42:06+00:00

Original question was I have a sqlite 3 db (a dictionary), that I want

  • 0

Original question was “I have a sqlite 3 db (a dictionary), that I want to use in a new app. Is there a short cut to creating the core data relationship model, based on the db structure?”

This is how I solved the problem – with lots of help all over the net.

I simplified the DB and that made writing the core data model pretty easy.

I used a Python script from this great site, to manage the conversion.

The script is as follows:

import sqlite3;

inConn = sqlite3.connect('dictold.sqlite')
outConn = sqlite3.connect('dictnew.sqlite')

inCursor = inConn.cursor()
outCursor = outConn.cursor()

maxId = 0
inCursor.execute("select * from lexicon")
for row in inCursor:

    if row[0] > maxId:
        maxId = row[0]

    # Create ZLEXICONENTITY entry
    vals = []
    vals.append(row[3]) # Z_PK
    vals.append(1) # Z_OPT
    vals.append(2) # Z_ENT  
    vals.append(row[0]) # ZIND
    vals.append(row[1]) # ZENGLISH
    vals.append(row[2]) # ZGREEK
    outConn.execute("insert into ZLEXICONENTITY values(?, ?, ?, ?, ?, ?)", vals)


outConn.execute("update Z_PRIMARYKEY set Z_MAX=?", [maxId])

outConn.commit()

Once I had the database built, I had a problem connecting it to the Core Data model. I got a message that the “model did not match the database”.

The solution is to let Core Data create the empty data base from the model, and then have Core Data import the data itself.

I first exported my sqlite database (created with Python) to sql calling the file db.sql (imaginative!). I only exported the data table and the primary key table, not the metadata table. You can also do this at the command line. I used an app called SQLiteManager.

All the code in Core Data is stock stuff except for handling the Persistent Store Controller..

That code is as follows:

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {

    if (persistentStoreCoordinator_ != nil) {
        return persistentStoreCoordinator_;
    }


    NSString *storePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"db.sql"];

    // set up the backing store
    NSFileManager *fileManager = [NSFileManager defaultManager];
    // If the expected store doesn't exist, copy the default store.
    if (![fileManager fileExistsAtPath:storePath]) {
        NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"dict" ofType:@"sqlite"];
        if (defaultStorePath) {
            [fileManager copyItemAtPath:defaultStorePath toPath:storePath error:NULL];
        }
    }

    NSURL *storeURL = [NSURL fileURLWithPath:storePath];

    NSError *error = nil;
    persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
    if (![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {

        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }    

    return persistentStoreCoordinator_;
}

Many probably know all this, but I had to tough it out for a few days. There are probably easier ways to do this too. But perhaps it will help others..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:42:07+00:00Added an answer on May 24, 2026 at 5:42 am

    No.

    Core Data cannot infer your model from your existing schema, you will have to create the model and then migrate the store on your own.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Original Question I want to be able to generate a new (fully valid) MP3
Original Question: i read that for RESTful websites. it is not good to use
Short Question I have a loop that runs 180,000 times. At the end of
Update is below code chunks. Original Question: I have an input field that is
REVISED QUESTION I have revised the original question (as seen below) so that I
Original Question I am looking for a function that attempts to quantify how distant
(The original question was asked there : http://www.ogre3d.org/phpBB2/viewtopic.php?t=44832 ) Someone asked : While I
SEE EDIT UPDATES BELOW. Original question has been modified! I have a working window
Update 2018 TL;DR; LaTEX for WPF https://github.com/ForNeVeR/wpf-math Original question I need to have a
I have a database that I built in SQLite browser, and it works fine.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.