i made a migration in my CI, now i have error in making some foreign key in it. How can i make some foreign key, i saw some questions here related to this topic but it doesn't solve my problem.
Here is my code where i got error:
public function up() {
$this->dbforge->add_field(array(
'student_id' => array(
'type' => 'INT',
'constraint' => 11,
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'course_id' => array(
'type' => 'INT',
'constraint' => 11,
),
'fname' => array(
'type' => 'VARCHAR',
'constraint' => 50,
),
'lname' => array (
'type' => 'VARCHAR',
'constraint' => 50,
),
'gender' => array (
'type' => 'VARCHAR',
'constraint' => 1
),
'bday' => array (
'type' => 'DATE'
)
));
$this->dbforge->add_key('student_id', TRUE);
$this->dbforge->add_field('CONSTRAINT FOREIGN KEY (course_id) REFERENCES tbl_course(id)');
$this->dbforge->create_table('tbl_students');
it gives me an error of :
Can't create table `student_db`.`tbl_students` (errno: 150 "Foreign key constraint is incorrectly formed")
CONSTRAINT FOREIGN KEY (course_id) REFERENCES tbl_course(id),
CONSTRAINT `pk_tbl_students` PRIMARY KEY(`student_id`)
) DEFAULT CHARACTER SET = utf8 COLLATE = utf8_general_ci