i have 2 tables 'pengguna' and 'mahasiswa' and then 1 have a form which is 1 form inserting into 2 tables, so far i manage to insert the data but when it has to do with "primary key" and "foreign key" it has problem, as u can see from code below id_pengguna from table pengguna is a primary key and id_pengguna from table mahasiswa is a foreign key the problem is when i inserting the data, id_pengguna from pengguna has it value while in table mahasiswa it has no value, below are my code, is there any simple way or am i doing something wrong?
PENGGUNA TABLE
MAHASISWA TABLE

Controller
public function insertMahasiswa(){
$username = $this->input->post('username');
$password = md5($this->input->post('password'));
$data1 = array(
'username'=>$username,
'password'=>$password,
'level'=>3,
);
$nim = $this->input->post('nim');
$nama = $this->input->post('nama');
$email = $this->input->post('email');
$telepon = $this->input->post('telepon');
$data = array(
'nim'=>$nim,
'nama_mahasiswa'=>$nama,
'email'=>$email,
'telepon'=>$telepon,
);
$insert = $this->MMahasiswa->create('pengguna',$data1);
$insert1 = $this->MMahasiswa->create('mahasiswa',$data);
redirect(site_url('mahasiswa/data?balasan=1'));
}
MODEL
function create($table,$data){
$query = $this->db->insert($table, $data);
return $query;
}