【问题标题】:MySQL error - I don't understand what it is sayingMySQL 错误 - 我不明白它在说什么
【发布时间】:2010-05-27 20:59:56
【问题描述】:

查询:

INSERT INTO `job_listing_has_employer_details` (`job_listing_id`, `employer_details_id`)
VALUES (6, '5')

错误:

无法添加或更新子行:外键约束失败(mydb.job_listing_has_employer_details, CONSTRAINT job_listing_has_employer_details_ibfk_2 FOREIGN KEY (employer_details_id) REFERENCES employer_details (id))

这是什么意思?我要插入到表中的两个 ID 存在。

【问题讨论】:

    标签: sql mysql


    【解决方案1】:

    表示在employer_details 表的id 列中找不到“5”。如果该表的该列中有 5,则数据可能是数字,因此必须不带引号传递。如果是这样,请尝试:

    INSERT INTO `job_listing_has_employer_details` (`job_listing_id`, `employer_details_id`) VALUES (6, 5) 
    

    【讨论】:

    • 我正在使用 PHP 将值转换为 int,但我仍然收到错误提示
    • select count(*) from employer_details where id = 6 的输出是什么?
    • 6 是 job_listing_id 而不是employer_details_id
    • 所以,让我们再试一次。 select count(*) from employer_details where id = 5 的输出是什么?
    猜你喜欢
    • 2018-05-22
    • 2020-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多