Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The DELETE statement conflicted with the REFERENCE

I have a table_Project with a CustomerID in it (linked to tbl_Customer). In tbl_Customer I have Customer_ID(as key) and some other info like Phone, Email etc.

To delete it from the Gridview I use this DeleteCommand:

DeleteCommand="DELETE FROM [tbl_Customer] WHERE [Customer_ID] = @Customer_ID" 

But it gives me the following error:

The DELETE statement conflicted with the REFERENCE constraint "Klant_Relatie". The conflict occurred in database "Database_1", table "dbo.tbl_Project", column 'CustomerID'. The statement has been terminated.

But with updating the CustomerInfo I do not get any error. I have seen different solutions for C# but I use .net

Any idea's?

like image 699
DiederikEEn Avatar asked Dec 21 '22 07:12

DiederikEEn


1 Answers

You cannot delete the client if he is referenced by a project.. That's what the error means..

I don't understand your

I have seen different solutions for C# but I use .net

But you have different solutions here:

  1. Change the client referenced by all projects linked to old one (the one you want to delete)
  2. Drop constraint (Not really good option)
  3. Delete project before deleting the client (manually or by using cascade delete)
like image 107
bAN Avatar answered Dec 29 '22 01:12

bAN