Skip to content
Microsoft Dynamics 365 Blog

Given scenario:

You receive the following failure when compiling the application:

The INSERT statement conflicted with the FOREIGN KEY constraint “FK_ModelElementData_HasModelId_LayerId”. The conflict occurred in database “YourDataBaseName_model”, table “dbo.Model”

 

Cause:

This might be caused by some metadata pieces that have offending <LayerId, ModelId> combination)

 

Resolution suggestion:

a. Disable the FK constraint from model database by running following SQL statement:

 EXEC sp_msforeachtable “ALTER TABLE ? NOCHECK CONSTRAINT all”

b. Do a full application compile

c. Run the following SQL query to check the affected objects :

 

select top 100 *from ModelElementData med

where not exists

( select 1 from UTILMODELS um where med.ModelId=um.ID and med.LayerId=Layer)

d. Take necessary actions to correct the affected objects 

e.  Enable the FK constraint again on your Model Database by running following SQL statement:

EXEC sp_msforeachtable “ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all”

f. Do a full XPP compilation and a full CIL generation

We're always looking for feedback and would like to hear from you. Please head to the Dynamics 365 Community to start a discussion, ask questions, and tell us what you think!

Join the conversation

Loading comments...