Hangfire.EntityFrameworkCore
Hangfire.EntityFrameworkCore copied to clipboard
ExpirationManager giving an exception
it seems that there are foreign keys between HangFireState table and HangFireJob table One of them is set to cascading delete and the other is not From SQL its relatively easy to adjust but perhaps you handle this in the migration scripts and in the entity model setup ?
SQL used to fix this
-- Drop foreign key
ALTER TABLE HangfireJob DROP FOREIGN KEY FK_HangfireJob_HangfireState_StateId;
-- -- Create foreign key
ALTER TABLE HangfireJob ADD CONSTRAINT FK_HangfireJob_HangfireState_StateId FOREIGN KEY (StateId) REFERENCES HangfireState(Id) ON DELETE CASCADE;
Traces
dbug: Hangfire.EntityFrameworkCore.ExpirationManager[0]
Removing outdated records from the 'HangfireCounter' table...
dbug: Hangfire.EntityFrameworkCore.ExpirationManager[0]
Removing outdated records from the 'HangfireHash' table...
dbug: Hangfire.EntityFrameworkCore.ExpirationManager[0]
Removing outdated records from the 'HangfireList' table...
dbug: Hangfire.EntityFrameworkCore.ExpirationManager[0]
Removing outdated records from the 'HangfireSet' table...
dbug: Hangfire.EntityFrameworkCore.ExpirationManager[0]
Removing outdated records from the 'HangfireJob' table...
dbug: Hangfire.Processing.BackgroundExecution[0]
Execution loop ExpirationManager:043fc230 caught an exception and will be retried in 00:03:45
Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while saving the entity changes. See the inner exception for details.
---> Cannot delete or update a parent row: a foreign key constraint fails (PLHFPORTAL
.HangfireJob
, CONSTRAINT FK_HangfireJob_HangfireState_StateId
FOREIGN KEY (StateId
) REFERENCES HangfireState
(Id
))
--- End of inner exception stack trace ---
at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(IEnumerable1 commandBatches, IRelationalConnection connection) at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IList
1 entriesToSave)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(StateManager stateManager, Boolean acceptAllChangesOnSuccess)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)
at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
at Hangfire.EntityFrameworkCore.ExpirationManager.<>c__61.<RemoveExpired>b__6_1(DbContext context) at Hangfire.EntityFrameworkCore.EFCoreStorage.UseContext[T](Func
2 func)
at Hangfire.EntityFrameworkCore.ExpirationManager.<RemoveExpired>b__6_0T
at Hangfire.EntityFrameworkCore.ExpirationManager.UseLock(Action action)
at Hangfire.EntityFrameworkCore.ExpirationManager.RemoveExpiredT
at Hangfire.EntityFrameworkCore.ExpirationManager.Execute(CancellationToken cancellationToken)
at Hangfire.Processing.BackgroundExecution.Run(Action`2 callback, Object state)
dbug: Hangfire.Processing.BackgroundExecution[0]
Execution loop ExpirationManager:043fc230 will be retried in 00:03:45...