我在Entityframework
中使用ASP.NET
创建了一个表格。我的数据库是MySQL
。我在我的MySQL上运行了SHOW CREATE TABLE
命令,得到了以下结果。
'AttendancePercentageDetails', 'CREATE TABLE `AttendancePercentageDetails` (\n `AttendancePercentageDetailsId` int(11) NOT NULL AUTO_INCREMENT,\n `Date` datetime NOT NULL,\n `Percentage` double NOT NULL,\n `SiteDetailsID` int(11) NOT NULL,\n `UserDetailsID` int(11) NOT NULL,\n PRIMARY KEY (`AttendancePercentageDetailsId`),\n KEY `IX_SiteDetailsID` (`SiteDetailsID`) USING HASH,\n KEY `IX_UserDetailsID` (`UserDetailsID`) USING HASH,\n CONSTRAINT `FK_AttendancePercentageDetails_UserDetails_UserDetailsID` FOREIGN KEY (`UserDetailsID`) REFERENCES `UserDetails` (`UserDetailsID`) ON DELETE CASCADE ON UPDATE CASCADE,\n CONSTRAINT `FK_AttendancePercentageDetails_SiteDetails_SiteDetailsID` FOREIGN KEY (`SiteDetailsID`) REFERENCES `SiteDetails` (`SiteDetailsId`) ON DELETE CASCADE ON UPDATE CASCADE\n) ENGINE=InnoDB AUTO_INCREMENT=812 DEFAULT CHARSET=latin1'
我正在尝试使用以下命令删除foreign key
UserDetailsID
。
SET foreign_key_checks = 0;
ALTER TABLE dbclockit.AttendancePercentageDetails DROP FOREIGN KEY UserDetailsID;
SET foreign_key_checks = 1;
MySQL抛出错误说
Error Code: 1091. Can't DROP 'UserDetailsID'; check that column/key exists
我跑了
SELECT * FROM dbclockit.AttendancePercentageDetails;
,输出中包含UserDetailsID
列。
答案 0 :(得分:1)
这很有用。
ALTER TABLE dbclockit.AttendancePercentageDetails DROP foreign key FK_AttendancePercentageDetails_UserDetails_UserDetailsID;
ALTER TABLE dbclockit.AttendancePercentageDetails DROP COLUMN UserDetailsID;