MySQL 在做某个表的外键关联时,提示如下错误

1215 - Cannot add foreign key constraint

后查,该表的存储引擎为 MyISAM

在 MySQL 的官方文档中提到,MyISAM 是 不支持外键的,“Foreign key support No”。

Storage limits256TBTransactionsNoLocking granularityTable
MVCCNoGeospatial data type supportYesGeospatial indexing supportYes
B-tree indexesYesT-tree indexesNoHash indexesNo
Full-text search indexesYesClustered indexesNoData cachesNo
Index cachesYesCompressed dataYes[a]Encrypted data[b]Yes
Cluster database supportNoReplication support[c]YesForeign key supportNo
Backup / point-in-time recovery[d]YesQuery cache supportYesUpdate statistics for data dictionaryYes

[a] Compressed MyISAM tables are supported only when using the compressed row format. Tables using the compressed row format with MyISAM are read only.

[b] Implemented in the server (via encryption functions), rather than in the storage engine.

[c] Implemented in the server, rather than in the storage engine.

[d] Implemented in the server, rather than in the storage engine.

参考 http://dev.mysql.com/doc/refman/5.7/en/myisam-storage-engine.html