[英]mysql errno 150 when creating foreign key
我得到errno 150,不知道為什么。 我已經讀過一百萬個其他答案,說您必須在父列上設置索引,但我不確定為什么我仍然會收到此錯誤。
父表索引:
mysql> show indexes from plans;
+-------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| plans | 0 | PRIMARY | 1 | plan_id | A | 86 | NULL | NULL | | BTREE | | |
| plans | 0 | plan_id_UNIQUE | 1 | plan_id | A | 86 | NULL | NULL | | BTREE | | |
| plans | 1 | plan_id | 1 | plan_id | A | 86 | NULL | NULL | | BTREE | | |
+-------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
3 rows in set (0.08 sec)
子表索引:
mysql> show indexes from promos;
+--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| promos | 0 | PRIMARY | 1 | promo_id | A | 0 | NULL | NULL | | BTREE | | |
| promos | 1 | plan_id | 1 | plan_id | A | 0 | NULL | NULL | | BTREE | | |
+--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
2 rows in set (0.06 sec)
錯誤:
mysql> alter table promos add foreign key (plan_id) references plans (plan_id) on delete cascade on update cascade;
ERROR 1005 (HY000): Can't create table 'dev.#sql-2ce_599a' (errno: 150)
兩列必須具有相同的排序規則和字符集。
這有效: http : //sqlfiddle.com/#!2/0f917
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.