search

Home  >  Q&A  >  body text

laravel foreign key constraint failed

1. The existing slave table score foreign key player_id is associated with the main table playerinfo primary key id.
2. When adding data to the slave table, an error occurred:
Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (racesys.score, CONSTRAINT score_player_id_foreign FOREIGN KEY (player_id) REFERENCES playerinfo (id)) (SQL: insert into score (id, player_id, node, childnode, time) values ​​(041be572-2ed5-3e01- ac2c-43bab35117e9, 00ec1635-0fd5-3481-a3d4-0afa4e8f66ea, 1, 1, 2007-05-23 14:38:26))"

3.
playerinfo primary key id attribute

]

score foreign key player_id attribute

Question: What is the reason for the foreign key constraint failure? How to solve?

高洛峰高洛峰2748 days ago860

reply all(1)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-16 16:48:55

    When adding the slave table, the foreign key must have data in the primary key of the master table.

    reply
    0
  • Cancelreply