DbUpdateException: An error occurred while saving the entity changes. See the inner exception for details.
SaveChanges failed in the database; the inner exception (SqlException/PostgresException) has the real reason — constraint violation, truncation, NULL, or deadlock.
Seen on:
.NET
Meaning
Always log ex.InnerException. Common inner errors: duplicate key (unique index), FK violation, string or binary data would be truncated, cannot insert NULL.
Common causes
- Unique constraint violation
- Foreign key violation
- String too long for the column
- NULL in a non-nullable column
⚡ Quick fix
- Log the inner exception message
- Fix the data or model constraints
- Validate before saving
Detailed fix by platform
C#
- csharp
try { await db.SaveChangesAsync(); } catch (DbUpdateException ex) { logger.LogError(ex.InnerException, "Save failed: {Msg}", ex.InnerException?.Message); throw; }
How to diagnose
- Inner — Exact database error
- Entity — ex.Entries list
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in .NET
- NullReferenceException System.NullReferenceException: Object reference not set to an instance of an object
- FileNotFoundException assembly Could not load file or assembly 'X, Version=…' or one of its dependencies
- InvalidOperationException InvalidOperationException: Unable to resolve service for type 'X' while attempting to activate 'Y'
Other ways to find it
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 7 Oct 2026