我有一个表名 coursemaster,它有 2 列课程代码和课程名称,另一个表 coursesubject 它有 2 列课程代码和主题代码,我应用了父子关系。当我在 coursemaster 中更新课程代码中的值时,它显示错误
#1451 - Cannot delete or update a parent row: a foreign key constraint fails (`latest`.`coursemaster`, CONSTRAINT `coursemaster_ibfk_1` FOREIGN KEY (`course_code`) REFERENCES `coursemaster` (`course_code`) ON UPDATE CASCADE)
但我想更新 ccoursemaster 表中的课程代码,它应该反映在 coursesubject 课程代码中。
我的 coursemaster 表结构
Field Type Collation Attributes Null Default Extra Action
id int(11) No None AUTO_INCREMENT Browse distinct values Change Drop Primary Unique Index Fulltext
course_code varchar(255) latin1_swedish_ci No Browse distinct values Change Drop Primary Unique Index Fulltext
course_name varchar(255) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext
索引:文档
Action Keyname Type Unique Packed Field Cardinality Collation Null Comment
Edit Drop PRIMARY BTREE Yes No course_code 13 A
Edit Drop id BTREE Yes No id 13 A
Edit Drop course_code BTREE Yes No course_code 13 A
课程科目结构
Field Type Collation Attributes Null Default Extra Action
id int(11) No None AUTO_INCREMENT Browse distinct values Change Drop Primary Unique Index Fulltext
course_code varchar(255) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext
subject_code varchar(255) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext
索引:文档
Action Keyname Type Unique Packed Field Cardinality Collation Null Comment
Edit Drop PRIMARY BTREE Yes No id 2 A
Edit Drop subject_code BTREE No No subject_code 2 A YES
Edit Drop courseindex BTREE No No course_code 2 A YES
subject_code 2 A YES