" SHOW CREATE TABLE order_products"的结果是
CREATE TABLE `order_products` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`quantity` int(11) NOT NULL,
`price` double DEFAULT NULL,
`amount` double(8,2) NOT NULL,
`product_id` int(10) unsigned NOT NULL,
`tax_id` int(10) unsigned DEFAULT NULL,
`discount_id` int(10) unsigned DEFAULT NULL,
`order_id` int(10) unsigned DEFAULT NULL,
`username` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`shop_name` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `order_products_product_id_foreign` (`product_id`),
KEY `order_products_tax_id_foreign` (`tax_id`),
KEY `order_products_discount_id_foreign` (`discount_id`),
KEY `order_products_order_id_foreign` (`order_id`)
) ENGINE=InnoDB AUTO_INCREMENT=40 DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_unicode_ci
我尝试删除我的密钥" order_products_product_id_foreign"由
ALTER TABLE order_products DROP FOREIGN KEY order_products_product_id_foreign
但它给了我错误
#1091 - Can't DROP 'order_products_product_id_foreign'; check that column/key exists
答案 0 :(得分:2)
您不需要在此处指定FOREIGN KEY关键字。
alter table order_products drop key order_products_product_id_foreign;
答案 1 :(得分:1)
这不是外键。因此执行该行。
ALTER TABLE order_products DROP KEY order_products_product_id_foreign