Monday, August 5, 2019

Replication Error ALTER Table Conflicted with the foreign key

Error:
The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "XXXX_ABCD_fk". The conflict occurred in database "TESTDB", table "dbo.TEST_event", column 'event_id'. (Source: MSSQLServer, Error number: 547)
Get help: http://help/547

Or

The DELETE statement conflicted with the REFERENCE constraint "XXXX_ABCD_item_fk". The conflict occurred in database "TESTDB", table "dbo.TEST_hist", column 'offer_item_id'.

I was facing above error, After reintialization in SQL Server replication on TESTDB.
I tried to find forigen key XXXX_ABCD_fk but it was deleted few days and it was not found in database.
To resolve this issue required to delete "MSsavedForeignKeys" forgein key in table at subscription database.


delete dbo.MSsavedForeignKeys where constraint_name = N’XXXX_ABCD_item_fk’

Latter replication SYNC worked fine for me.