简体   繁体   中英

mysql foreign key mistake

I need help about this issue. There is a problem but I could not find it

error message is

Cannot add or update a child row: a foreign key constraint fails ( db_kiosk . tbl_oyunhareketi , CONSTRAINT OH_KioskID FOREIGN KEY ( OH_KioskID ) REFERENCES tbl_kiosk ( Kiosk_ID ) ON DELETE NO ACTION ON UPDATE NO ACTION)

Here is my code c#

string sql = "insert into db_kiosk.tbl_oyunhareketi (OH_OyuncuID,OH_KioskID,OH_Puan,OH_Tarih,OH_ControlRow) values ('"+Convert.ToInt32(Label4.Text)+"','"+Convert.ToInt32(Label3.Text)+"','" + Puan_txt.Text + "' , '" + Tarih_txt.Text + "',1)";

Label3.Text = Kiosk_Drop.SelectedValue;

Label4.Text = Oyuncu_Drop.SelectedValue;

Kiosk_Drop and Oyuncu_Drop are the dropdownlist in ASP.net and they are in the selectedIndexChanged function. When I display the labels the values are coming properly but problem is insertion. DB attributes also integer but I couldn't find the problem.

You have foreign key constraint that prevents you from adding rows to the child table before you have relevant information in the parent table.

In this case you should first populate tbl_kiosk before adding a row to tbl_oyunhareketi . Rows are matched by columns OH_KioskID and Kiosk_ID .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM