MySQL删除外键错误152

xyl*_*lar 13 mysql foreign-keys alter-table

我试图使用以下方法删除一些外键:

ALTER TABLE `table` DROP FOREIGN KEY `fk_table_users1` , DROP FOREIGN KEY `fk_table_accounts1` , DROP FOREIGN KEY `fk_table_data1` ;
Run Code Online (Sandbox Code Playgroud)

但它返回错误:

Error on rename of './db/table' to './db/#sql2-179c-288289' (errno: 152)
Run Code Online (Sandbox Code Playgroud)

我跑SHOW ENGINE INNODB STATUS了说:

120725 12:38:37 Error in dropping of a foreign key constraint of table db/table,
in SQL command
ALTER TABLE `table` DROP FOREIGN KEY `fk_table_users1` , DROP FOREIGN KEY `fk_table_accounts1` , DROP FOREIGN KEY `fk_table_data1` 
Cannot find a constraint with the given id fk_table_users1.
Run Code Online (Sandbox Code Playgroud)

SHOW CREATE TABLE 'table' 输出:

CREATE TABLE `table` (
 `id` int(11) NOT NULL auto_increment,
 `data_id` int(11) NOT NULL,
 `account_id` int(11) NOT NULL,
 `status` enum('pending','complete') NOT NULL default 'pending',
 `created_at` datetime NOT NULL,
 `created_by` int(11) NOT NULL,
 PRIMARY KEY  (`id`),
 KEY `fk_orders_users1` (`created_by`),
 KEY `fk_orders_data1` (`data_id`),
 KEY `fk_orders_accounts1` (`account_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
Run Code Online (Sandbox Code Playgroud)

但是,当我通过phpmyadmin查看结构时,它会列出具有相同名称的外键.在丢弃外键之前,我还需要做些什么吗?

jsi*_*ist 11

没有外键.请参阅MySQL文档它说

KEY is normally a synonym for INDEX.
Run Code Online (Sandbox Code Playgroud)

所以基本上在表中你创建了索引,而不是外键.有关外键信息,请单击此处