Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

The UPDATE statement conflicted with the FOREIGN KEY constraint

Posted on by 450

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.


  • Suggested answer
    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
    Albert_ 450 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
    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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans