添加外键时出现错误代码#1452

时间:2014-08-17 15:04:44

标签: mysql sql

错误

SQL查询:

ALTER TABLE `bids` ADD  FOREIGN KEY (`buyerID`) REFERENCES `e_trading_post`.`buyer`(`buyerID`) 
ON DELETE CASCADE ON UPDATE CASCADE;
MySQL说:

  
    

1452 - 无法添加或更新子行:外键约束失败(' e_trading_post'。#sql-15d48_6a8',CONSTRAINT`#sql-15d48_6a8_ibfk_1' FOREIGN KEY(' buyerID')参考'买方;(' buyerID')ON DELETE CASCADE ON UPDATE CASCADE)

  

1 个答案:

答案 0 :(得分:1)

此错误表示无法创建此特定外键约束,因为它将被违反(现在已被违反)。

以下查询可能会帮助您找到违规行:

select buyerID from bids where buyerID not in (select buyer from e_trading_post)