gpt4 book ai didi

php - 键存在于表中,但在 MySQL 中显示 Can't Drop foreign key

转载 作者:太空宇宙 更新时间:2023-11-03 11:30:15 26 4
gpt4 key购买 nike

“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

我尝试删除我的 key “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

最佳答案

您无需在此处指定 FOREIGN KEY 关键字。

alter table order_products drop key order_products_product_id_foreign;

关于php - 键存在于表中,但在 MySQL 中显示 Can't Drop foreign key,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50655026/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com