解决 mysql 插入数据报错: Cannot add or update a child row: a foreign key constraint fails
前些天發(fā)現(xiàn)了一個(gè)巨牛的人工智能學(xué)習(xí)網(wǎng)站,通俗易懂,風(fēng)趣幽默,忍不住分享一下給大家。點(diǎn)擊跳轉(zhuǎn)到教程。
場(chǎng)景:我的情況是主表為用戶(hù) user 表,從表為職位 job 表,其中 job 表有一個(gè)外鍵為 user 表的主鍵。
我想要往 job 表中 insert 一條數(shù)據(jù),報(bào)錯(cuò)如題。
?
原因:要插入 job 表的數(shù)據(jù)中外鍵列的值有問(wèn)題,userId 字段的值在 user 表中找不到。
?
解決: 確保 job 表中要引用的外鍵值在 user 表中有對(duì)應(yīng)數(shù)據(jù)就可以了。
?
“ you're adding a foreign key, you need to make sure that the data in the child table already exists in the parent table . ”
參考:https://www.experts-exchange.com/questions/28238845/1452-Cannot-add-or-update-a-child-row-a-foreign-key-constraint-fails.html
總結(jié)
以上是生活随笔為你收集整理的解决 mysql 插入数据报错: Cannot add or update a child row: a foreign key constraint fails的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Qt-Focus事件处理,重写qpush
- 下一篇: Qt-qwidget项目入门实例