Error deploying project from Team City

I am using a build step within TeamCity to deploy a web application via Octopus. I’ve deployed this app many times (including a few times today). This afternoon I tried deploying it with a small verbiage change and got the following error in TeamCity:

Unable to create or deploy a release.

I looked into the build logs and saw this error: Error from Octopus server (HTTP 500): Octopus Server returned an error:

Error while executing SQL command: Violation of PRIMARY KEY constraint ‘PK_Deployment_Id’. Cannot insert duplicate key in object ‘dbo.Deployment’. The duplicate key value is (Deployments-3196).

The packages were successfully created in Octopus in the “Library” section with the appropriate package version numbers.

I also tried disabling the Octopus Deploy step in TeamCity and manually creating a release and deploying the application in Octopus and got a similar SQL error:

Error while executing SQL command: Violation of PRIMARY KEY constraint ‘PK_ServerTask_Id’. Cannot insert duplicate key in object ‘dbo.ServerTask’. The duplicate key value is (ServerTasks-27120). The statement has been terminated. The command being executed was: INSERT INTO dbo.[ServerTask] (Name, Description, QueueTime, StartTime, CompletedTime, ErrorMessage, ConcurrencyTag, State, HasPendingInterruptions, HasWarningsOrErrors, ServerNode, ProjectId, EnvironmentId, Id, Json) values (@Name, @Description, @QueueTime, @StartTime, @CompletedTime, @ErrorMessage, @ConcurrencyTag, @State, @HasPendingInterruptions, @HasWarningsOrErrors, @ServerNode, @ProjectId, @EnvironmentId, @Id, @Json)

TeamCity Enterprise version: 2017.1.2
Octopus version: 3.3.27

Any help with this issue would be greatly appreciated.

Hi Evania,

Thanks for getting in touch.

It looks like our key allocater is issuing keys that are already in use. The allocater may be out of sync with the database, in which case you could try restarting the Octopus Server. If that doesn’t help could you please run the following queries on your Octopus Deploy database and send the result:

SELECT *  FROM [dbo].[KeyAllocation]

SELECT MAX(Id) FROM [dbo].[ServerTask]

Thanks,
Shane