node_save() null tid column I am trying to create a node programatically like so, 

$newNode = (object) NULL;
$newNode-&gt;type = 'job';
$newNode-&gt;title = $data['JobTitle'];
$newNode-&gt;uid = $user-&gt;uid;
$newNode-&gt;created = strtotime("now");
$newNode-&gt;changed = strtotime("now");
$newNode-&gt;status = 1;
$newNode-&gt;comment = 0;
$newNode-&gt;promote = 0;
$newNode-&gt;moderate = 0;
$newNode-&gt;sticky = 0;
$newNode-&gt;tid = 0;

$newNode-&gt;summary['und'][0]['value'] = $data['JobSummary'];
$newNode-&gt;body['und'][0]['value'] = $data['JobDescription'];
$newNode-&gt;field_employment_type['und'] = strtolower($data['JobType']);
$newNode-&gt;field_job_reference['und'][0]['value'] = $data['JobReference'];
$newNode-&gt;field_salary['und'][0]['value'] = "";
$newNode-&gt;field_salary_from['und'][0]['value'] = $data['SalaryFrom'];
$newNode-&gt;field_salary_to['und'][0]['value'] = $data['SalaryTo'];
$newNode-&gt;field_salary_override['und'][0]['value'] = $data['Salary'];
$newNode-&gt;field_application_email['und'][0]['value'] = $data['ApplicationEmail'];
$newNode-&gt;field_job_category['und'][2] = 2;
$newNode-&gt;field_job_category['und'][4] = 4;

//die(print_r($newNode));
// save node
node_save($newNode);


Here I have potentially 4 taxonomies to pick from (their id indicated in brackets) Creative (2), Technical (3), Marketing (4), Client Services (6).

On node_save I am getting the following error,


  500 Internal Server Error : An error occurred (23000):
  SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'tid'
  cannot be null


How do I overcome this this I would have thought setting the field_job_category to the id of the taxonomy would be enough?
If you have one tid by node use:

$tid = 0;    
$newNode-&gt;taxonomy[0]-&gt;tid = $tid;


if the node can have more than one term use:

$tids = [0, 3, 4, 5];
$i = 0;
foreach ($tids as $tid) {
  $newNode-&gt;taxonomy[$i]-&gt;tid = $tid;
  $i++;
}