# DbUpdateException: An error occurred while saving the entity changes. See the inner exception for details.

**Code:** `DbUpdateException` · **Category:** .NET · **Seen on:** .NET

SaveChanges failed in the database; the inner exception (SqlException/PostgresException) has the real reason — constraint violation, truncation, NULL, or deadlock.

## 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

1. Log the inner exception message
2. Fix the data or model constraints
3. Validate before saving

## Detailed fix by platform

### C#

1. 

```csharp
try { await db.SaveChangesAsync(); }
catch (DbUpdateException ex) { logger.LogError(ex.InnerException, "Save failed: {Msg}", ex.InnerException?.Message); throw; }
```


## How to diagnose

1. **Inner** — Exact database error
2. **Entity** — ex.Entries list

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/dotnet/dbupdateexception-see-inner-exception)
