data
と の間に2 つ目の外部キー制約を追加したいと考えていますcontainers
。コンテナを削除すると、このコンテナにリンクされているデータも削除する必要があります。
テーブル:
mysql> DESCRIBE data;
+------------------------+--------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+--------------+------+-----+---------------------+----------------
| imei | varchar(15) | NO | MUL | NULL |
mysql> DESCRIBE containers;
+--------------------+-------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+-------------+------+-----+---------------------+----------------+
| imei | varchar(15) | NO | MUL | NULL | |
次のステートメントで外部キーを作成します。
mysql> ALTER TABLE `data` ADD FOREIGN KEY (`imei`) REFERENCES `containers`(`imei`) ON DELETE CASCADE;
Query OK, 15168 rows affected (0.12 sec)
Records: 15168 Duplicates: 0 Warnings: 0
しかし、外部キーは作成されていません:
mysql> use INFORMATION_SCHEMA;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME, REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME from KEY_COLUMN_USAGE where REFERENCED_TABLE_NAME = 'containers';
+----------------+-------------+-----------------------+-----------------------+------------------------+
| TABLE_NAME | COLUMN_NAME | CONSTRAINT_NAME | REFERENCED_TABLE_NAME | REFERENCED_COLUMN_NAME |
+----------------+-------------+-----------------------+-----------------------+------------------------+
| container_logs | imei | container_logs_ibfk_1 | containers | imei |
+----------------+-------------+-----------------------+-----------------------+------------------------+
1 row in set (0.16 sec)
私は何を間違っていますか?