[英]Unable to DROP a MySQL Table
我需要从MySQL数据库中删除一个已弃用的空表。
表定义是noddy:
CREATE TABLE IF NOT EXISTS `Address` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`ContactId` int(11) NOT NULL,
PRIMARY KEY (`Id`),
KEY `ContactId` (`ContactId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
这导致了
#1217 - Cannot delete or update a parent row: a foreign key constraint fails
ContactId有一个限制,但我已删除它。
PHPMyAdmin的导出函数不会显示除上面显示的表定义之外的任何内容。 表中没有行,据我所知,没有FK引用Address.Id
字段(但我不知道如何验证这一点)。
有人可以建议我如何摆脱桌子?
SET FOREIGN_KEY_CHECKS = 0;
DROP TABLE Address;
SET FOREIGN_KEY_CHECKS = 1;
列出外键
select
concat(table_name, '.', column_name) as 'foreign key',
concat(referenced_table_name, '.', referenced_column_name) as 'references'
from
information_schema.key_column_usage
where
referenced_table_name is not null;
对于您的情况下的特定搜索:
select
constraint_name
from
information_schema.key_column_usage
where
referenced_table_name = 'Address' AND referenced_column_name = 'ContactId';
要删除外键约束:
ALTER TABLE [table_name] DROP FOREIGN KEY [constraint_name];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.