How to delete data in two tables foreign key relationships

Between the table with the foreign key table can be established through contact with each other, as shown:
Here Insert Picture Description
Here Insert Picture Description
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};
Published 27 original articles · won praise 1 · views 837

Guess you like

Origin blog.csdn.net/weixin_44971379/article/details/105211628