title: Null on Foreign Key
body: <p>I have two tables : Invoice_stat and PMLprojects.</p>
  
  <p>EER Diagram :
  Invoice_stat<br>
  - invoice_id INT(11)<br>
  - other fields<br><br></p>
  
  <p>PMLProjects<br>
  -id int(11)<br>
  - other fields<br><br></p>
  
  <p>Relation :<br>
  Invoice_stat<br>
  Name : PMLProjects<br>
  Count : One<br>
  Ownership : blank<br><br></p>
  
  <p>Name : Invoice_stat<br>
  Count : Many<br>
  Ownership : blank<br><br></p>
  
  <p>(sorry, I want to put picture actually, but I need more reputation to put picture :)</p>
  
  <p>One project sometime have many Invoice, because it's invoice generated monthly.</p>
  
  <p>When I check on table, it show foreign_key on invoice_stat table. </p>
  
  <pre><code>CREATE TABLE `Invoice_stat` (
   `Invoice_id` int(11) NOT NULL AUTO_INCREMENT,
   `EmailStatus` varchar(255) DEFAULT NULL,
   `PaidStatus` varchar(255) DEFAULT NULL,
   `Invoice_Number` int(11) DEFAULT NULL,
   `DateCreate` datetime DEFAULT NULL,
   `PMLprojects_fk` int(11) DEFAULT NULL,
   PRIMARY KEY (`Invoice_id`),
   KEY `PMLprojects_fk` (`PMLprojects_fk`),
   CONSTRAINT `Invoice_stat_ibfk_1` FOREIGN KEY (`PMLprojects_fk`) REFERENCES `PMLprojects` (`Id`)
  ) ENGINE=InnoDB AUTO_INCREMENT=190145 DEFAULT CHARSET=utf8 |
  </code></pre>
  
  <p>but, when I check on PMLproject table, no foreign key.</p>
  
  <p>My problem is, when I create record in Invoice_stat, with click a button, it always show NULL on Invoice_stat table (PMLprojects_fk).</p>
  
  <p>To create table on Invoice_stat, I use script on server :</p>
  
  <pre><code>function createCaseStatusWithItem() {
   // Automatically number todo lists for the user.
   var lock = LockService.getScriptLock();
   lock.waitLock(10000);
   var query = app.models.Invoice_stat.newQuery();
   var allTodoLists = query.run();
   var todoList = app.models.Invoice_stat.newRecord();
   now = new Date();
  
  todoList.Invoice_id;
   todoList.Invoice_Number = allTodoLists.length + 1;
   todoList.EmailStatus = "Yes";
   todoList.PaidStatus = "No";
   todoList.DateCreate = now;
  
   app.saveRecords([todoList]);
   lock.releaseLock();
  
   } 
  </code></pre>
  
  <p>How to fix this problem ?</p>