Я создал таблицу с уникальным индексом и внешним индексом. Когда я добавляю уникальный ключ, я получаю успешный ответ от MySQL. Затем, когда я добавляю внешний ключ, я также получаю ответ об успешном выполнении.
Вот SQL для добавления внешнего ключа:
ALTER TABLE `rewards_customer_index_points`
ADD CONSTRAINT FOREIGN KEY FK_CUSTOMER_INDEX_POINTS_CUSTOMER_ID( `customer_id` )
REFERENCES `customer_entity` ( `entity_id` )
ON DELETE CASCADE
ON UPDATE CASCADE
Однако я не вижу этот внешний ключ на столе, поэтому, похоже, он не был успешно создан. Но он определенно есть, поскольку каскад работает, когда я удаляю указанную запись customer_entity.
Почему он не отображается в моем списке индексов? Обе таблицы InnoDB.
Вот структура таблицы и ключи на ней:
mysql> explain rewards_customer_index_points;
+-----------------+------------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+------------------+------+-----+-------------------+-----------------------------+
| index_points_id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| customer_id | int(10) unsigned | NO | MUL | NULL | |
| status | int(11) | NO | | 0 | |
| points_positive | int(11) | NO | | NULL | |
| points_negative | int(11) | NO | | NULL | |
| updated_at | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+-----------------+------------------+------+-----+-------------------+-----------------------------+
show index from rewards_customer_index_points;
+-------------------------------+------------+------------------------+--------------+-----------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------------------------------+------------+------------------------+--------------+-----------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| rewards_customer_index_points | 0 | PRIMARY | 1 | index_points_id | A | 2 | NULL | NULL | | BTREE | | |
| rewards_customer_index_points | 0 | idx_customer_id_status | 1 | customer_id | A | 2 | NULL | NULL | | BTREE | | |
| rewards_customer_index_points | 0 | idx_customer_id_status | 2 | status | A | 2 | NULL | NULL | | BTREE | | |
+-------------------------------+------------+------------------------+--------------+-----------------+-----------+-------------+----------+--------+------+------------+---------+---------------+