FK_ModelElementData_HasModelId_LayerId error

Given Error:
SQL error description: [Microsoft][SQL Server Native Client 11.0][SQL Server]The INSERT statement conflicted with the FOREIGN KEY constraint "FK_ModelElementData_HasModelId_LayerId". The conflict occurred in database "DbName_model", table "dbo.Model".

  1. Disable the FK constraint from model database by running following SQL statement:
    ALTER TABLE dbo.ModelElementData NOCHECK CONSTRAINT all;
    or disable all constraints on all tables
    EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all";
  2. Do compilation of objects that fail with error above. Or do a full application compile.
  3. Run the following SQL query to check the affected objects :
    select top 100 * from dbo.ModelElementData AS med
    where not exists
    (select 1 from dbo.UTILMODELS AS um where med.ModelId=um.ID and med.LayerId=Layer)
  4. Take actions to correct the affected objects. For example set correct combination of ModelId and LayerId.
    UPDATE dbo.ModelElementData SET ModelId = 1478 WHERE ElementHandle=1049983;
    or
    UPDATE dbo.ModelElementData SET ModelId = 1478 WHERE ElementHandle IN
    (
        select ElementHandle from dbo.ModelElementData AS med
        where not exists
        (select 1 from dbo.UTILMODELS AS um where med.ModelId=um.ID and med.LayerId=Layer)
    )

  5. Enable the FK constraint again on your Model Database by running following SQL statement:
    ALTER TABLE dbo.ModelElementData WITH CHECK CHECK CONSTRAINT all;
    or
    EXEC sp_msforeachtable "ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all";
  6. Do a full XPP compilation and a full CIL generation

Search

About

DaxOnline.org is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics AX.

Authors are allowed to set their own AdSense units.
Join us.

Blog Tags