"Could not drop constraint" error when applying a patch on an archive database
Symptoms
The following error occurs when applying GP 18.02.101.000 on an archive database:
FK_DailyDistribution_DemandItems is not a constraint. Could not drop constraint.
Reason
Foreign keys that are being dropped and recreated by the patch do not exist in the archive database.
Resolution
This is a known issue, which has been addressed in Changepoint 2020.
To bypass the error, execute the following query on the archive database:
IF OBJECT_ID('dbo.DailyDistribution') IS NOT NULL AND NOT EXISTS(SELECT TOP 1 1 FROM sys.foreign_keys WHERE name ='FK_DailyDistribution_DemandItems')
ALTER TABLE [dbo].[DailyDistribution] WITH CHECK ADD CONSTRAINT [FK_DailyDistribution_DemandItems] FOREIGN KEY([ID])
REFERENCES [dbo].[DemandItems] ([ID])
GO