Core Data SQLite store appears corrupted only when using migratePersistentStore

  • I am trying to migrate a persistent store from SQLite to binary type.
    The SQLite store seems to be working OK -- I can read, edit and write
    files -- however, when I try to migrate a know "good" file, I get an
    error.

    Here is the code snippet to migrate NSPersistentDocument *doc:

    NSPersistentStoreCoordinator* psc = [[doc managedObjectContext]
    persistentStoreCoordinator];
    id oldStore = [psc persistentStoreForURL:[doc fileURL]];
    NSError* error = nil;
    [psc migratePersistentStore:oldStore toURL:newURL
    options:nil withType:LIBRARY_STORE_TYPE error:&error];

    The console message I get is the following:

    2008-01-06 13:25:42.755 MyApp[1331] Fetch instances of entity
    (NSEntityDescription) name Analysis, managedObjectClassName Analysis,
    isAbstract 1, superentity name (null), properties {

    ...<many lines deleted here>...

    }, subentities {

    ...<many lines deleted here>...

    }, userInfo {} from store <NSSQLCore: 0x1632b510> failed, reason:
    NSError "The file could not be opened because it is not in the right
    format." Domain=NSCocoaErrorDomain Code=259 UserInfo={
        NSUnderlyingException = Fatal error.  The database at /Users/
    davef/Library/Application Support/MyApp/Library.nlib is corrupted.
    SQLite error code:1;
    }

    Can anyone shed some light on why the file only appears to be
    corrupted when I try to migrate it?

    Thanks in advance,
    Dave Fernandes
  • On Jan 6, 2008, at 1:45 PM, Dave Fernandes wrote:

    > I am trying to migrate a persistent store from SQLite to binary
    > type. The SQLite store seems to be working OK -- I can read, edit
    > and write files -- however, when I try to migrate a know "good"
    > file, I get an error.

    [...]

    > Can anyone shed some light on why the file only appears to be
    > corrupted when I try to migrate it?

    If the file is corrupt (as opposed to a misleading error message),
    migrating would be more likely to expose the problem since it reads
    every nook and cranny of the file whereas your typical fetch/insert/
    update does not.

    You can use the sqlite3 command line tool with "pragma
    integrity_check;" to find out whether sqlite thinks the file is
    corrupt or not.

    Jim
  • sqlite3 integrity_check says the file is "ok". I also tried vacuuming
    the file for good measure, but Core Data still can't migrate it.
    (Same error message as before.)

    On Jan 6, 2008, at 2:10 PM, Jim Correia wrote:

    > On Jan 6, 2008, at 1:45 PM, Dave Fernandes wrote:
    >
    >> I am trying to migrate a persistent store from SQLite to binary
    >> type. The SQLite store seems to be working OK -- I can read, edit
    >> and write files -- however, when I try to migrate a know "good"
    >> file, I get an error.
    >
    > [...]
    >
    >> Can anyone shed some light on why the file only appears to be
    >> corrupted when I try to migrate it?
    >
    > If the file is corrupt (as opposed to a misleading error message),
    > migrating would be more likely to expose the problem since it reads
    > every nook and cranny of the file whereas your typical fetch/insert/
    > update does not.
    >
    > You can use the sqlite3 command line tool with "pragma
    > integrity_check;" to find out whether sqlite thinks the file is
    > corrupt or not.
    >
    > Jim
    >
  • The problem is that I changed an entity in the managed object model
    after creating the SQLite store. Since none of the entities in the
    store were of the changed entity type, I didn't run into any problems
    using the store. It looks like Core Data must compare managed object
    models and throw this exception if anything has changed, even if the
    differing entities are not used in the store.

    The fix was to copy the objects in the corrupt store one-by-one into
    a new NSPersistentDocument, and save that new document. Then migrate
    this new document to a binary store.

    Dave

    On Jan 6, 2008, at 2:40 PM, Dave Fernandes wrote:

    > sqlite3 integrity_check says the file is "ok". I also tried
    > vacuuming the file for good measure, but Core Data still can't
    > migrate it. (Same error message as before.)
    >
    >
    > On Jan 6, 2008, at 2:10 PM, Jim Correia wrote:
    >
    >> On Jan 6, 2008, at 1:45 PM, Dave Fernandes wrote:
    >>
    >>> I am trying to migrate a persistent store from SQLite to binary
    >>> type. The SQLite store seems to be working OK -- I can read, edit
    >>> and write files -- however, when I try to migrate a know "good"
    >>> file, I get an error.
    >>
    >> [...]
    >>
    >>> Can anyone shed some light on why the file only appears to be
    >>> corrupted when I try to migrate it?
    >>
    >> If the file is corrupt (as opposed to a misleading error message),
    >> migrating would be more likely to expose the problem since it
    >> reads every nook and cranny of the file whereas your typical fetch/
    >> insert/update does not.
    >>
    >> You can use the sqlite3 command line tool with "pragma
    >> integrity_check;" to find out whether sqlite thinks the file is
    >> corrupt or not.
    >>
    >> Jim
    >>

previous month january 2008 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today