在控制器外部使用CodeIgniter模型,插入失败直到至少一个查询

I have a CI project I want to use with a 'raw' HTTP request, and I want to load the model and reuse that logic. That all sort of works, but I'm having trouble with inserting data.

I have one table, let's just call it 'foo' with one column 'bar' of varchar(4096).

I cannot insert data in to 'foo' until I query the database at least once, it doesn't matter what table.

include '../external.php';
error_reporting ( E_ALL );
ini_set ( 'display_errors', 1 );

$CI =& get_instance();
$CI->load->library('session');
$CI->load->database();

where 'external.php' is basically a copy of index.php modified to suppress output.

If I do:

    $data = array("bar" => $foo);
    $this->db->insert (self::TABLE, $data);
    return $this->db->insert_id();

In my model I get back:

        INSERT INTO `foo` (`bar`) VALUES ('')

which is clearly not right.

Any idea why doing a query first (for anything, for instance you can do a $this->db->count_all('unrelated_table'); and then the INSERT above has a value in the 'bar' column.