Answer the question
In order to leave comments, you need to log in
MySQL: Foreign key error?
I am writing a client in C# for a database on MySQL (connection via mysql.Net connector) I encountered such a problem.
Given are reference tables and a pivot table.
For example, one of the directories Counterparties
, add a new counterparty to it,
the code of the save button
try
{
this.Validate();
this.contragentBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.contractDataSet);
this.contractsDataGridView.Update();
MessageBox.Show("Данные обновлены успешно!", "Договоры", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch
{
MessageBox.Show("Ошибка обновления данных!", "Договоры", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Answer the question
In order to leave comments, you need to log in
I didn’t write clients in C#, but are you sure that the transaction is committed when a new counterparty is added?
Make a request to edit the contract, see what data they want to insert, then see if there is a foreign key in the database with which you are trying to add a record.
Look for inconsistencies there, but most likely, as already said, the transaction commit does not go through until the exit from the client.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question