且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySQL不为外键创建索引

更新时间:2022-11-08 18:40:33

您的外键确实具有索引.

Your foreign keys do have indexes.

MySQL在很多情况下都将KEYINDEX当作同义词.

MySQL treats the words KEY and INDEX are synonyms in many contexts.

请参见在MySQL中使用INDEX与KEY有什么区别?

重新更新问题.

我认为Django负责定义额外的KEY patients_membercard_b5c3e75b (member_id).它不会自动创建.也就是说,如果我在没有该KEY定义的情况下测试您的CREATE TABLE语句,则FOREIGN KEY不需要它.外国密钥可以使用唯一密钥的左列member_id.

I think Django is responsible for defining the extra KEY patients_membercard_b5c3e75b (member_id). It is not created automatically. That is, if I test your CREATE TABLE statement without that KEY definition, the FOREIGN KEY doesn't need it. The FOREIGN KEY can use the left column member_id of the UNIQUE KEY.

我猜想创建Django的开发人员无法处理这种情况.他们假定每个FOREIGN KEY都需要自己的索引,并且他们更喜欢确保可以控制索引名称.因此,它们在CREATE TABLE语句中显式生成索引的定义.

I am guessing that the developers who created Django didn't handle this case. They assume that every FOREIGN KEY needs its own index, and they prefer to make sure that they can control the index name. So they generate a definition of an index explicitly in the CREATE TABLE statement.