title: Core data bug refers to nonexistent core data attribute of reflexive many-to-many relationship
body: <p>I am experiencing a perplexing Core Data bug, in which I receive the following error message when trying to save some data: </p>
  
  <pre><code>CoreData: error: (1) I/O error for database at /var/mobile/Applications/5D3C0F3C-E097-43BF-887B-2870B1148226/Documents/Database.sqlite.  SQLite error code:1, 'table Z_1RELATEDCARDS has no column named FOK_REFLEXIVE'
  
  Core Data: annotation: -executeRequest: encountered exception = I/O error for database at /var/mobile/Applications/5D3C0F3C-E097-43BF-887B-2870B1148226/Documents/Database.sqlite.  SQLite error code:1, 'table Z_1RELATEDCARDS has no column named FOK_REFLEXIVE' with userInfo = {
  
      NSFilePath = "/var/mobile/Applications/5D3C0F3C-E097-43BF-887B-2870B1148226/Documents/Database.sqlite";
  
      NSSQLiteErrorDomain = 1;
  
  }
  </code></pre>
  
  <p>For some context: there is no column "reflexive" in my data model. I have an entity, Cards, which has an attribute, relatedCards, that is a many-to-many relationship between Card items. I am quite confused as to what this error is referring to, and any assistance would be greatly appreciated.</p>
  
  <hr>
  
  <p><strong>UPDATE</strong></p>
  
  <p>As per a great suggestion in the comments, I ran the app in the iOS Simulator with the argument <code>-com.apple.CoreData.SQLDebug 3</code> and received the following response:</p>
  
  <pre><code>CoreData: annotation: Connecting to sqlite database file at "/Users/jason/Library/Application Support/iPhone Simulator/5.0/Applications/4EE6D378-A946-4EBF-9849-F7D2E58F2776/Documents/Database.sqlite"
  CoreData: sql: pragma cache_size=200
  CoreData: sql: BEGIN EXCLUSIVE
  CoreData: sql: UPDATE ZCARD SET ZDATEMODIFIED = ?, Z_OPT = ?  WHERE Z_PK = ? AND Z_OPT = ?
  CoreData: details: SQLite bind[0] = "338478797.092588"
  CoreData: details: SQLite bind[1] = (int64)7
  CoreData: details: SQLite bind[2] = (int64)119
  CoreData: details: SQLite bind[3] = (int64)6
  CoreData: sql: UPDATE ZCARD SET ZDATEMODIFIED = ?, Z_OPT = ?  WHERE Z_PK = ? AND Z_OPT = ?
  CoreData: details: SQLite bind[0] = "338478797.092577"
  CoreData: details: SQLite bind[1] = (int64)7
  CoreData: details: SQLite bind[2] = (int64)100
  CoreData: details: SQLite bind[3] = (int64)6
  CoreData: sql: INSERT OR REPLACE INTO Z_1RELATEDCARDS(Z_1RELATEDCARDS, REFLEXIVE, FOK_REFLEXIVE) VALUES (119, 100, 0)
  CoreData: annotation: Disconnecting from sqlite database due to an error.
  CoreData: error: (1) I/O error for database at /Users/jason/Library/Application Support/iPhone Simulator/5.0/Applications/4EE6D378-A946-4EBF-9849-F7D2E58F2776/Documents/Database.sqlite.  SQLite error code:1, 'table Z_1RELATEDCARDS has no column named FOK_REFLEXIVE'
  [Switching to process 45402 thread 0x15503]
  </code></pre>
  
  <p>For a little context, I have modified the Card table to keep track of when it is modified. That's what's going on in the upper portion of the debug output. However, the key line in the debug output is clearly the fourth from the bottom:</p>
  
  <pre><code>CoreData: sql: INSERT OR REPLACE INTO Z_1RELATEDCARDS(Z_1RELATEDCARDS, REFLEXIVE, FOK_REFLEXIVE) VALUES (119, 100, 0)
  </code></pre>
  
  <p>I went into my SQLite database and checked, there is no column <code>FOK_REFLEXIVE</code> in this table. The schema for this table is:</p>
  
  <pre><code>CREATE TABLE Z_1RELATEDCARDS ( Z_1RELATEDCARDS INTEGER, REFLEXIVE INTEGER, PRIMARY KEY (Z_1RELATEDCARDS, REFLEXIVE) );
  </code></pre>
  
  <p>So clearly, Core Data is trying to insert data into a field which does not exist. What am I supposed to do with this?</p>
  
  <h2>Update:</h2>
  
  <p>This is also an issue reported by users. I can't update my app and just tell users "oh well you need to trash your data store and start over." That won't go over very well unfortunately even if it were the cause of this error.</p>