Jump to content

Lesson Learned #276: ALTER TABLE statement conflicted with the CHECK constraint importing a bacpac


Recommended Posts

Guest Jose_Manuel_Jurado
Posted

Today, I worked on a service request where our customer faced the following error: The ALTER TABLE statement conflicted with the CHECK constraint "Table1". The conflict occurred in database "DatabaseName", table "Table2".

 

 

 

Full error message:

 

Microsoft.Data.Tools.Diagnostics.Tracer Verbose: 0 : 2023-01-11T11:11:35 : Executing Step 341, Not Tracked, Type 'EnableConstraintsStep', Section 'None', Operation '0', Ignorable Errors 'None', Script is as follows: PRINT N'Checking constraint: table1_table2_updatedby_foreign [dbo].[Table1]'; ALTER TABLE [dbo].[Table1] WITH CHECK CHECK CONSTRAINT [table1_table2_updatedby_foreign];

 

Microsoft.Data.Tools.Diagnostics.Tracer Error: 19 : 2023-01-11T11:11:39 : Retry requested: Retry count = 1. Delay = 00:00:00.2500000, SQL Error Code = -2146232060, SQL Error Number = 547, Can retry error = True, Will retry = True Microsoft.Data.SqlClient.SqlException (0x80131904): The ALTER TABLE statement conflicted with the CHECK constraint "Table1". The conflict occurred in database "DatabaseName", table "Table2". Error Number:547,State:0,Class:16

 

 

 

This situation happened at the moment that the process has inserted all the rows in all tables and needs to enable the constrains/indexes. Points that a foreign key doesn't exist in the related table. You could see more details here "For an export to be transactionally consistent, you must ensure either that no write activity is occurring during the export, or that you are exporting from a transactionally consistent copy of your database." based on this link

 

 

 

The solution is to export the data again, avoiding any writing operation in the database during this process. After it, initiate again the import process.

 

 

 

Enjoy!

 

Continue reading...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...