Between the table with the foreign key table can be established through contact with each other, as shown:
Note: If you want to build two tables foreign key relationship, the corresponding field type size should be consistent
The following discussion of data to establish a foreign key relationships how to delete:
Items used in the table id table of students as their foreign key, you can not delete the data when you delete a table of students, as they may be referenced in the program will be given: as follows
Cannot delete or update a parent row: a foreign key constraint fails (`test`.`good`, CONSTRAINT `stu_good` FOREIGN KEY (`stu_id`) REFERENCES `student` (`id`))
You should delete the data to establish a foreign key relationships
delete from good where id=#{id};
delete from student where id=#{id};