Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 402 Vote(s) - 3.39 Average
  • 1
  • 2
  • 3
  • 4
  • 5
INSERT statement conflicted with the FOREIGN KEY constraint - SQL Server

#11
I used code-first migrations to build my database for an MVC 5 application. The seed method in my configuration.cs file was causing the issue, creating a table entry for the table containing the foreign key before creating the entry with the matching primary key.
Reply

#12
1. run sp_helpconstraint
2. pay attention to the constraint_keys column returned for the foreign key
Reply

#13
That error means that the table you are inserting data into has a foreign key relationship with another table. Before data can be inserted, the value in the foreign key field **must** exist in the other table first.
Reply

#14
The error you're encountering is due to a violation of the FOREIGN KEY constraint `FK_Sup_Item_Sup_Item_Cat` when attempting to insert a value into the client_id column of the sup_item table. The error message indicates that the value you're trying to insert does not exist in the referenced table Sup_Item_Cat in the dev_bo database.

To resolve this issue, you should ensure that the value you're inserting into the client_id column matches an existing value in the referenced table Sup_Item_Cat. You can verify the available values in the `Sup_Item_Cat` table and make sure you're providing a valid client_id.

Here's an example query to retrieve the existing client_id values from the Sup_Item_Cat table:

SELECT client_id
FROM dbo.Sup_Item_Cat;

Review the output of this query and confirm that the value you're trying to insert into the client_id column exists in the `Sup_Item_Cat` table.

[![enter image description here][1]][1]

To identify which other tables and columns a particular table depends on, you can use the information from the Keys folder and Depends on [dbForge Studio for SQL Server.][2]


[1]:

[2]:

[To see links please register here]

Reply

#15
I experienced same issue while running the query:

```
INSERT INTO [dbo].[work_flow_actions] ([work_flow_id] ,[actions_id]) VALUES (70004, 150044)
```

Meanwhile, I confirmed that the values 70004 and 150044 exist in the corresponding tables.

I fixed this by including the database name as follows:

```
INSERT INTO [TIS].[dbo].[work_flow_actions] ([work_flow_id] ,[actions_id]) VALUES (70004, 150044)
```
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through