title: node-sqlite3 Serialization fails : SQLITE_CONSTRAINT: foreign key constraint failed
body: <p>In Express.js I am trying to do the following using the serialization of two queries where the second one depends on the first one:</p>
  
  <ol>
  <li>I am trying to get an entryID using the first query</li>
  <li>I use that entryID for the second query</li>
  </ol>
  
  <p>As far as I understand, the second query is called before the first one completes. Also the "console.log("My entry: "+data.entryID);" returns the right entryID. Below I have shown the code I am using as well as the error I get. Any help would be appreciated.</p>
  
  <pre><code>db.serialize(function(){
  
      db.get("Select entryID from entry where pID=$pID",{$pID:participName},function(err, data){
          if(err) throw err;
          foundID=data.entryID;
          console.log("My entry: "+data.entryID);
          });
  
          db.run("insert into observation(entryID, objID, data) values($entryID,1,$intro_counter)", {$entryID:foundID, $intro_counter:intro_counter});
  
  });
  
  
   events.js:71
      throw arguments[1]; // Unhandled 'error' event
                     ^
   Error: SQLITE_CONSTRAINT: foreign key constraint failed
  </code></pre>