web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :

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

Dynamics AX Support Profile Picture Dynamics AX Support

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 *fromModelElementDatamed

where notexists

( select 1 fromUTILMODELSumwheremed.ModelId=um.IDandmed.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

Comments

*This post is locked for comments