解决 mysql 插入数据报错: Cannot add or update a child row: a foreign key constraint fails
生活随笔
收集整理的這篇文章主要介紹了
解决 mysql 插入数据报错: Cannot add or update a child row: a foreign key constraint fails
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
前些天發現了一個巨牛的人工智能學習網站,通俗易懂,風趣幽默,忍不住分享一下給大家。點擊跳轉到教程。
場景:我的情況是主表為用戶 user 表,從表為職位 job 表,其中 job 表有一個外鍵為 user 表的主鍵。
我想要往 job 表中 insert 一條數據,報錯如題。
?
原因:要插入 job 表的數據中外鍵列的值有問題,userId 字段的值在 user 表中找不到。
?
解決: 確保 job 表中要引用的外鍵值在 user 表中有對應數據就可以了。
?
“ 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
總結
以上是生活随笔為你收集整理的解决 mysql 插入数据报错: Cannot add or update a child row: a foreign key constraint fails的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Qt-Focus事件处理,重写qpush
- 下一篇: Linux 查看 MySQL 版本的四种