php - 表中存在键,但在 MySQL 中显示 Can't Drop foreign key
问题描述
“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
解决方案
您无需在此处指定 FOREIGN KEY 关键字。
alter table order_products drop key order_products_product_id_foreign;
推荐阅读
- python - 错误:找不到满足 matplotlib 要求的版本(来自版本:无) 错误:找不到 mathplotlib 的匹配分布
- akka.net - 如何覆盖自定义日志的 PersistenceTestKit 配置?
- package.json - 如何解决:./src/reportWebVitals.js 中的错误语法错误:'import' 和 'export' 可能只出现在顶层
- neovim - BufWritePost 链接命令
- processing - 如何通过单击鼠标右键停止处理绘制循环?
- php - 如何在 Laravel 8 的编辑刀片中选中单选按钮
- reactjs - 如何在 MUI GridList 中实现瓦片的水平滚动?
- c# - 在 C# 中根据行号从 csv 文件中删除行/行
- javascript - 使用选择列表对项目列表进行排序的正确方法是什么
- mercurial - Mercurial:使用 .hg 目录和工作树在单独的目录中跟踪 repo