The INSERT statement conflicted with the FOREIGN KEY constraint  "FK_tableName_key". The conflict occurred in database  "Database Name", table "dbo.tableName", column 'id'


Question: How do you resolve the error that says: 
The INSERT statement conflicted with the FOREIGN KEY constraint 
"FK_tableName_key". The conflict occurred in database 
"Database Name", table "dbo.tableName", column 'id'.".


Login to See the Rest of the Answer

Answer:
While it is a good idea to have Foreign Keys in the Database Schema, sometimes it can be hard to migrate data from one Database to another. For example, the dependency of one column on another tables column can hinder data migration.

The way you solve the error described above is by first importing the data that the table with a Foreign Key relys on, then import the data the table with a Foreign Key has.

If the above does not work, it would be prudent to say that maybe you need to invaluete the denomalizing the Database Schema, too many Foreign Keys sometimes creates problems than it intends to solve.

Additional Logs you might see:

- Copying to [dbo].[TableName] (Error)
Messages
Information 0x402090df: Data Flow Task 1: The final commit for the data insertion in "Destination 2 - [TableName]" has started.
 (SQL Server Import and Export Wizard)
 
Information 0x402090e0: Data Flow Task 1: The final commit for the data insertion  in "Destination 2 - [TableName]" has ended.
 (SQL Server Import and Export Wizard)
 
Information 0x402090df: Data Flow Task 1: The final commit for the data insertion in "Destination 3 - [TableName]" has started.
 (SQL Server Import and Export Wizard)
 
Information 0x402090e0: Data Flow Task 1: The final commit for the data insertion  in "Destination 3 - [TableName]" has ended.
 (SQL Server Import and Export Wizard)
 
Error 0xc0202009: Data Flow Task 1: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80004005.
An OLE DB record is available.  Source: "Microsoft SQL Server Native Client 11.0"  Hresult: 0x80004005  Description: "The statement has been terminated.".
An OLE DB record is available.  Source: "Microsoft SQL Server Native Client 11.0"  Hresult: 0x80004005  Description: "The INSERT statement conflicted with the FOREIGN KEY constraint "FK_user_log". The conflict occurred in database , table "[TableName]", column 'id'.".
 (SQL Server Import and Export Wizard)
 
Error 0xc0209029: Data Flow Task 1: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR.  The "Destination 1 - [TableName].Inputs[Destination Input]" failed because error code 0xC020907B occurred, and the error row disposition on "Destination 1 - [TableName].Inputs[Destination Input]" specifies failure on error. An error occurred on the specified object of the specified component.  There may be error messages posted before this with more information about the failure.
 (SQL Server Import and Export Wizard)
 
Error 0xc0047022: Data Flow Task 1: SSIS Error Code DTS_E_PROCESSINPUTFAILED.  The ProcessInput method on component "Destination 1 - [TableName]" (84) failed with error code 0xC0209029 while processing input "Destination Input" (97). The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running.  There may be error messages posted before this with more information about the failure.
 (SQL Server Import and Export Wizard)
 
Error 0xc02020c4: Data Flow Task 1: The attempt to add a row to the Data Flow task buffer failed with error code 0xC0047020.
 (SQL Server Import and Export Wizard)
 
Error 0xc0047038: Data Flow Task 1: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED.  The PrimeOutput method on Source - [TableName] returned error code 0xC02020C4.  The component returned a failure code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing.  There may be error messages posted before this with more information about the failure.
 (SQL Server Import and Export Wizard)
 
Error 0xc02020c4: Data Flow Task 1: The attempt to add a row to the Data Flow task buffer failed with error code 0xC0047020.
 (SQL Server Import and Export Wizard)
 
Error 0xc0047038: Data Flow Task 1: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED.  The PrimeOutput method on Source 4 - user_log returned error code 0xC02020C4.  The component returned a failure code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing.  There may be error messages posted before this with more information about the failure.
 (SQL Server Import and Export Wizard)
 





SQL
published
v.0.01




For peering opportunity Autonomouse System Number: AS401345 Custom Software Development at ErnesTech Email AddressContact: [email protected]