MariaDB sakhtrade alter table catalog_products add foreign key type ty

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
MariaDB [sakhtrade]> alter table catalog_products add foreign key `type` (type_id) references catalog_product_types(id) on delete set null;
ERROR 1005 (HY000): Can't create table `sakhtrade`.`#sql-2331_33` (errno: 121 "Duplicate key on write or update")
MariaDB [sakhtrade]> show indexes from catalog_products;
+------------------+------------+-------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+------------------+------------+-------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| catalog_products | 0 | PRIMARY | 1 | id | A | 0 | NULL | NULL | | BTREE | | |
| catalog_products | 1 | category_id | 1 | category_id | A | 0 | NULL | NULL | YES | BTREE | | |
| catalog_products | 1 | name | 1 | name | A | 0 | NULL | NULL | YES | BTREE | | |
| catalog_products | 1 | price | 1 | price | A | 0 | NULL | NULL | YES | BTREE | | |
| catalog_products | 1 | sort_order | 1 | sort_order | A | 0 | NULL | NULL | YES | BTREE | | |
| catalog_products | 1 | path | 1 | path | A | 0 | NULL | NULL | YES | BTREE | | |
+------------------+------------+-------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
6 rows in set (0.00 sec)
MariaDB [sakhtrade]> alter table catalog_products add foreign key `type_1` (type_id) references catalog_product_types(id) on delete set null;
Query OK, 0 rows affected (0.55 sec)
Records: 0 Duplicates: 0 Warnings: 0