Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL工作台:如何为具有3个主键(A、B、C)的表定义2个外键关系(A、B)和(B、C)_Mysql_Mysql Workbench - Fatal编程技术网

MySQL工作台:如何为具有3个主键(A、B、C)的表定义2个外键关系(A、B)和(B、C)

MySQL工作台:如何为具有3个主键(A、B、C)的表定义2个外键关系(A、B)和(B、C),mysql,mysql-workbench,Mysql,Mysql Workbench,我试图在MySQL工作台中建立一个MySQL模型 到目前为止,我已经定义了三个表:studentTerm,studentTerm课程,课程表。表studentTerm课程有3个主键:{studentId,courseCode和termCode,其中studentId和courseCode是studentTerm表的主键,courseCode>和termCode是courseTerm表的主键 我试图在studentTerm课程中定义外键,但无法在与courseTerm表相关的外键名称中选择term

我试图在MySQL工作台中建立一个MySQL模型

到目前为止,我已经定义了三个表:
studentTerm
studentTerm课程
课程表
。表
studentTerm课程
有3个主键:
{studentId,courseCode和termCode
,其中
studentId
courseCode
studentTerm
表的主键,
courseCode>和
termCode
courseTerm
表的主键

我试图在
studentTerm课程
中定义外键,但无法在与
courseTerm
表相关的外键名称中选择
termCode
,因为我已经将其定义为与
studentTerm
表相关的外键

我希望下面的屏幕截图能更清楚地说明这一点:

您能建议定义主键/外键的正确方法吗

谢谢。

确保两个表中的列的数据类型完全相同(例如,unsigned)

这可能与键顺序有关。您是否尝试过
courseCode
然后在
courseTerm
中使用
termCode
?@DaveCast感谢您的回复。在实施您的建议时,我意识到了真正的问题-我在其他两个表(即studentTerm和studentTermCourse)中使用了未签名的termCode但不是在courseTerm中。(只是从SQL开始)