MySQL MyISAM 添加外键失败
MySQL 在做某个表的外键关联时,提示如下错误
1215 - Cannot add foreign key constraint
后查,该表的存储引擎为 MyISAM
在 MySQL 的官方文档中提到,MyISAM 是 不支持外键的,“Foreign key support No”。
Storage limits | 256TB | Transactions | No | Locking granularity | Table |
MVCC | No | Geospatial data type support | Yes | Geospatial indexing support | Yes |
B-tree indexes | Yes | T-tree indexes | No | Hash indexes | No |
Full-text search indexes | Yes | Clustered indexes | No | Data caches | No |
Index caches | Yes | Compressed data | Yes[a] | Encrypted data[b] | Yes |
Cluster database support | No | Replication support[c] | Yes | Foreign key support | No |
Backup / point-in-time recovery[d] | Yes | Query cache support | Yes | Update statistics for data dictionary | Yes |
[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