无法删除MySQL表

Bas*_*sic 3 mysql sql foreign-keys

我需要从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 ;
Run Code Online (Sandbox Code Playgroud)

这导致了

#1217 - Cannot delete or update a parent row: a foreign key constraint fails

ContactId有一个限制,但我已删除它.

PHPMyAdmin的导出函数不会显示除上面显示的表定义之外的任何内容.表中没有行,据我所知,没有FK引用该Address.Id字段(但我不知道如何验证这一点).

有人可以建议我如何摆脱桌子?

bcm*_*cfc 13

SET FOREIGN_KEY_CHECKS = 0;
DROP TABLE Address;
SET FOREIGN_KEY_CHECKS = 1;
Run Code Online (Sandbox Code Playgroud)


Nat*_*n Q 8

列出外键

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;
Run Code Online (Sandbox Code Playgroud)

对于您的情况下的特定搜索:

select 
    constraint_name
from
    information_schema.key_column_usage
where
    referenced_table_name = 'Address' AND referenced_column_name = 'ContactId';
Run Code Online (Sandbox Code Playgroud)

要删除外键约束:

ALTER TABLE [table_name] DROP FOREIGN KEY [constraint_name];
Run Code Online (Sandbox Code Playgroud)