E
E
egorggegor2020-07-19 15:52:33
Database administration
egorggegor, 2020-07-19 15:52:33

How to fix FOREIGN KEY error?

There are two tables /Users/egortimonin/Desktop/Screenshot 2020-07-19 at 15.48.25.png in tblMessage all IDs are unique, but EQUIPMENT_ID can be repeated, when filling the tblMessage table SQL complains and writes

Конфликт инструкции INSERT с ограничением FOREIGN KEY "FK__tblMessag__EQUIP__0559BDD1". 
Конфликт произошел в базе данных "dbo", таблица "dbo.tblEquipment", column 'ID'.
I don't understand why this is happening, I have a one-to-many relationship where one tblEquipment entry can have many entries in the tblMessage table. Why is there an error?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Tsvetkov, 2020-07-19
@egorggegor

You are adding to a tblMessagestring with a value EQUIPMENT_IDthat is not in tblEquipment.

K
kisaa, 2020-07-19
@kisaa

The screenshot is not visible, but I will assume that you mixed up the direction of the key (i.e. the unique field).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question