【发布时间】:2012-07-23 20:19:37
【问题描述】:
我正在尝试使用以下方法删除一些外键:
ALTER TABLE `table` DROP FOREIGN KEY `fk_table_users1` , DROP FOREIGN KEY `fk_table_accounts1` , DROP FOREIGN KEY `fk_table_data1` ;
但它返回错误:
Error on rename of './db/table' to './db/#sql2-179c-288289' (errno: 152)
我运行了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.
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
但是,当我通过 phpmyadmin 查看结构时,它会列出具有相同名称的外键。在删除外键之前我需要做其他事情吗?
【问题讨论】:
-
请发布
SHOW CREATE TABLE `table`;的输出。 -
@eggyal 用输出编辑了我的帖子
-
我没有看到 any 外键约束...
-
感谢您指出这一点。我们使用迁移脚本,看起来它没有添加外键
标签: mysql foreign-keys alter-table