20

I'm really stuck here with upgrade testing from v1 to v2 of an iPhone application. I have IPA releases that I'm testing via ad hoc distribution via iTunes to my iPhone device, one for v1 of the app and one for v2. Note that:

  • v1 installs runs fine on my device
  • if I delete v1 and deploy v2 (so no migration) then it works fine
  • when I deploy v2 whilst v1 is already there I get the error: "reason=Can't find model for source store"

A snippet from the error...*

reason=**Can't find model for source store**}, {
         URL = "file://localhost/var/mobile/Applications/AAAAF424-D6ED-40FE-AB8D-66879386739D/Documents/MyApp.sqlite";
         metadata =     {
             NSPersistenceFrameworkVersion = 320;
             <cut>
  • when I use "phone disk" to look at my device I see there is Documents/MyApp.sqlite file

Question - Any ideas how to resolve this? What debugging/analysis could I do here? Let me know if you need any more info.

What I have done as an overview is:

PS fuller version of error if this helps - this time it comes from simulating the migration error on the simulator

, reason=Can't find model for source store}, {
    URL = "file://localhost/Users/greg/Library/Application%20Support/iPhone%20Simulator/4.3.2/Applications/69FDFDCF-631D-4191-B852-CD75151B1EA9/Documents/MyApp.sqlite";
    metadata =     {
        NSPersistenceFrameworkVersion = 320;
        NSStoreModelVersionHashes =         {
            Config = <5f92f988 71e11a66 554ae924 61887562 22b8de8a c318b110 e3e4a569 81adafa2>;
        };
        NSStoreModelVersionHashesVersion = 3;
        NSStoreModelVersionIdentifiers =         (
            ""
        );
        NSStoreType = SQLite;
        NSStoreUUID = "3B9832DA-E3A1-431B-83E8-43431A7F3452";
    };
    reason = "Can't find model for source store";
}

PSS. If this helps the contents of the core data model *.mom directory/package for each version archieve are:

v1

-rw-r--r--   1 greg  staff  1664  5 Sep 21:06 MyApp.mom
-rw-r--r--   1 greg  staff  2656  5 Sep 21:06 MyApp.omo
-rw-r--r--   1 greg  staff   480  5 Sep 21:06 VersionInfo.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd>">
  <plist version="1.0">
    <dict>
      <key>NSManagedObjectModel_CurrentVersionName</key>
      <string>MyApp</string>
      <key>NSManagedObjectModel_VersionHashes</key>
      <dict>
        <key>MyApp</key>
        <dict>
          <key>Config</key>
          <data>
            X5L5iHHhGmZVSukkYYh1YiK43orDGLEQ4+SlaYGtr6I=
          </data>
        </dict></dict></dict>
      </plist>

v2

-rw-r--r--  1 greg  staff   497  2 Oct 12:47 MyApp 1.mom
-rw-r--r--  1 greg  staff  1601  2 Oct 12:47 MyApp 2.mom
-rw-r--r--  1 greg  staff  1695  2 Oct 12:47 MyApp.mom
-rw-r--r--  1 greg  staff  2920  2 Oct 12:47 MyApp.omo
-rw-r--r--  1 greg  staff   665  2 Oct 12:47 VersionInfo.plist

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd>">
  <plist version="1.0">
    <dict>
      <key>NSManagedObjectModel_CurrentVersionName</key>
      <string>MyApp</string>
      <key>NSManagedObjectModel_VersionHashes</key>
      <dict>
        <key>MyApp</key>
        <dict>
          <key>Config</key>
          <data>
            Z/n8092QBHPfBwInZvIm1lei53T1UtZhpNzjl3JA0gs=
          </data>
        </dict>
        <key>MyApp 1</key>
        <dict/>
        <key>MyApp 2</key>
        <dict>
          <key>Config</key>
          <data>
            Fih24clI+kZszFd3X6Gm8itq8YDxudiKnjHW8ydNmps=
          </data>
        </dict></dict></dict>
      </plist>

EDIT: Another question that is not clear to me, as raised by reviewing the link jrturton provided below is:

  1. How does one now in the latest XCode version do the "Set Current Version" to the appropriate model version file? i.e. the previous posts highlights two different steps being one Adding Model Version, but then separately "Set Current Version"
  2. How is one supposed to use the Core Data Model "identifier" field which one can set for each of the core data model files. It's in the inspector. The parameter exists against for example the MyApp 1.xcdatamodel, MyApp 2.xcdatamodel, and MyApp.xcdatamodel files, so what do you need to put in each one here?
tshepang
  • 12,111
  • 21
  • 91
  • 136
Greg
  • 34,042
  • 79
  • 253
  • 454
  • Does this help? http://stackoverflow.com/questions/2310216/implementation-of-automatic-lightweight-migration-for-core-data-iphone – jrturton Oct 02 '11 at 06:39
  • thanks - the point 1 & 3 didn't help, but as for point 2 - do you know how one would carry out this point in the latest version of XCode4? That is "Select your xcdatamodel file Design -> Data Model -> Add Model Version (expand your xcdatamodeld item) Select the “2″ (or later) file, Design -> Data Model -> Set Current Version (edit this version)". I'll elaborate more on this at the bottom of my question... – Greg Oct 02 '11 at 09:34

4 Answers4

37

You set the version of your data model in the Utilities inspector (right hand pane), under the Identity and Type tab when the xcdatamodeld file is selected. This has a section called "Core Data Model", and a field called "Identifier".

You add a new model version by selecting the xcdatamodeld file, the going to Editor --> Add model version.

At this point it prompts you for the previous model to base it on.

If youve added a new model without going through this process the lightweight migration may not work.

jrturton
  • 118,105
  • 32
  • 252
  • 268
  • thanks jrturton - can I clarify please (a) so re the "Identifier" field does this have to be an integer I guess? As long as the values keep increasing? (b) does the naming of each new model version matter? i.e. XCode automatically puts an increasing number at the end of each new file, (c) so the first model file xcode creates without a number at end, it could be used for v1 then I guess...that is there's nothing special about the first xcdatamodel file xcode creates versus subsequent versions is there? – Greg Oct 02 '11 at 20:57
  • think I've finally made sense of it – Greg Oct 04 '11 at 03:10
  • 1
    @greg I had the same issue. Can you please explain what I need to do with "identifier". In my initial version I didn't set any value to "identifier" is that cause any issue?. – Naveen Shan Jul 18 '12 at 17:41
  • In newest versions of Xcode there is a 'Model Version' subheading on the Identity and Type tab with a dropdown where you can pick what the current data model is without typing it into the 'Identifier' part – Chris Klingler Sep 25 '13 at 03:22
  • @sn0wfreeze you'll have to be more specific. You should ask a separate question. – jrturton Apr 20 '14 at 16:45
  • I think Xcode thought I edited the original model, so it wasn't possible to load the new version. I reproduced the steps again and it worked. – Sn0wfreeze Apr 22 '14 at 05:00
3

another thing that can cause this, is if you:

  1. make version 2
  2. then edit version 1 accidentally
  3. then make version 2 default
  4. realize your change isn't there
  5. make your change again on version 2

you get the same effect, because the version 1 that you are trying to merge from isn't the version that created the store.

Grady Player
  • 14,399
  • 2
  • 48
  • 76
1

If you made changes to your model and you made sure that you generated a model object AND don't care about the migration nor are interested in making a new version, you simply need to do a Product -> Clean and that will typically fix this issue.

If you are still having this error, locate your sqlite DB and delete it. When you launch the app again it will make a new one that's built from the new model.

Alternatively, you can delete the app from the simulator or, if all else fails, tap on "iOS Settings" at the top of simulator and select "Reset Content and Settings..." and it will quickly wipe the simulator so you can start fresh.

Travis M.
  • 10,930
  • 1
  • 56
  • 72
0

Xcode 8, i had this issue without doing migration

Can't find model for source store

what i did is simply

Simulator > Reset Content and Settings
Ted
  • 22,696
  • 11
  • 95
  • 109