0

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)
4

1 に答える 1