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 :
Customer experience | Sales, Customer Insights,...
Answered

The UPDATE statement conflicted with the FOREIGN KEY constraint

(0) ShareShare
ReportReport
Posted on by 458

I am doing something not standard, but I have to do.
I am gonna update CRM365 database from previous backup; with a query.
I had created two custom entity.

One named service.
Another named service name.
Service name is look up in service entity; so it has 1:N relationship with service entity.
The relation was referential.
Unfortunately a client had delete access and has deleted the two record of Service name entity.

Likewise Service name look up field of every records of Service that had those two deleted records are null now !
Now when write update query  between two databases and two tables it return me :

The UPDATE statement conflicted with the FOREIGN KEY constraint "reltion_name". The conflict occurred in database "x", table "service_nameBase", column 'service_namesId'.
I query the extentionbase table of related entity,which is service and update that with column of my backup database.
I have created a test environment and do my works there.
As I run the query it gives me the above error.
I googled and find out this is because of relation between them.
The primary key of the Service Name is the foreign key of the Service.

How can I solve this problem?
I changed relation between them from referential to configurable cascading and set all configuration to cascade all.
But no success.
I know that this job is not recommended, But as I said I have to.
These two entities are both custom and non-system entity.Any help will appreciate.


I have the same question (0)
  • Suggested answer
    Ankit Sabharwal Profile Picture
    on at
    RE: The UPDATE statement conflicted with the FOREIGN KEY constraint

    Can you please paste the thread link in this post and mark my post verified if it helped you

  • Albert_ Profile Picture
    458 on at
    RE: The UPDATE statement conflicted with the FOREIGN KEY constraint

    Thanks,

    That worked for me in test environment!

    But something horrible happened in real environment .

    Check the next thread !

  • Verified answer
    Ankit Sabharwal Profile Picture
    on at
    RE: The UPDATE statement conflicted with the FOREIGN KEY constraint

    Hy Albert,

    Hope this finds you well. As you have said that running an update , being part of the community we all know that it is unsupported, but if you have to adopt a suggestion, there is one which cross my mind now. If we disable Foreign key constraint on the table and then update the records and then re-enable it, may work in this case. How to diable the foreign key from SQL Management studio object explorer, I found an article as below :-

    https://docs.microsoft.com/en-us/sql/relational-databases/tables/disable-foreign-key-constraints-with-insert-and-update-statements?view=sql-server-ver15

    To disable a foreign key constraint for INSERT and UPDATE statements

    1. In Object Explorer, expand the table with the constraint and then expand the Keys folder.

    2. Right-click the constraint and select Modify.

    3. In the grid under Table Designer, click Enforce Foreign Key Constraint and select No from the drop-down menu.

    4. Click Close.

    Kindly note this is unsupported change what we are doing and we are not sure what complications it can cause.

    Hope this helps.

    Best regards,

    Ankit

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
DAnny3211 Profile Picture

DAnny3211 136

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 130

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 70 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans