Primary key constraint error while trying to add or update any entity (such as deployment process, environment etc)

Sodiq Yusuf's Avatar

Sodiq Yusuf

12 Sep, 2017 07:45 AM

So we moved our octopus database to another server but after doing this, we could not add or update an environment, deployment process or any other thing again. I have attached the screenshot of this issue. I would be so glad to receive a response as soon as possible as this issue is causing a serious downtime in our operations. I am running Octopus 3.12.7

  1. 1 Posted by Vanessa Love on 13 Sep, 2017 04:32 AM

    Vanessa Love's Avatar


    Sorry that you have run into this issue. It occurs when your Event index ID is behind. We aren't sure why this occurs but we have seen it once before.

    You will need to complete the following to reset the ID:

    1. Shutdown Octopus Deploy (stop the service)
    2. Create a full backup of the database
    3. Run the following SQL (you may want to download SQL Server Management Studio from to run the script):
      DECLARE @maxVal INT
      SELECT @maxVal = ISNULL(max(ID),0)+1 from octopus.dbo.EventRelatedDocument
      DBCC CHECKIDENT('octopus.dbo.EventRelatedDocument', RESEED, @maxVal)

    Please let me know if that helps.

  2. 2 Posted by Sodiq Yusuf on 13 Sep, 2017 09:28 AM

    Sodiq Yusuf's Avatar

    Thank you so much, Vanessa, it now works after running that script.

  3. 3 Posted by Vanessa Love on 14 Sep, 2017 04:49 AM

    Vanessa Love's Avatar


    Glad to hear that fixed the issue. As i'm sure you can understand this isn't something we want to ever occur, and we would like to investigate how it occurred.
    Are you at all willing to provide us with your database backup? I can provide a secure location to upload it, and we do not require the masterkey thus won't be able to see any secure information.

    Please let me know.

  4. Paul Stovell closed this discussion on 19 Dec, 2017 06:33 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac