Can anyone explain this error to me? [closed]

-2

I have 2 tables, products and suppliers. And the following message is appearing:

  

System.Data.SqlClient.SqlException: 'The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Products_Provider". The "C: \ USERS \ TIAGO \ DOCUMENTS \ VISUAL STUDIO 2017 \ PROJECTS \ PROJECTS \ FINAL WORK POO \ FINAL WORK POO \ BD.MDF", table "dbo.support", column 'cnpj'.

Can anyone explain this error to me?

    
asked by anonymous 22.05.2018 / 02:28

2 answers

2

The error is very clear, foreign key conflict ... You are trying to insert into the [Produtos] table a product with a Vendor that does not exist, in the case in the CNPJ column, which appears to be your fk

    
22.05.2018 / 02:35
1

Insert it into the [Suppliers] table before inserting it into the [Products] table. This will allow the database to find the record of the vendor you are trying to reference in the insert that is displaying an error.

    
22.05.2018 / 03:00