# 列“email”中的空值违反了非空约束

- **ID:** `python/sqlalchemy-flush-error-null-violation`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

尝试插入或更新行时，未为非空列提供值，导致数据库完整性错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **Provide required values explicitly** (95% 成功率)
   ```
   Ensure all NOT NULL columns are assigned values before flush/commit, e.g., user.email = 'user@example.com'.
   ```
2. **Alter column to allow NULL** (80% 成功率)
   ```
   Modify the database schema to allow NULL if appropriate, using ALTER TABLE or migration.
   ```

## 无效尝试

- **Adding default=None to column** —  (50% 失败率)
- **Calling flush() instead of commit()** —  (40% 失败率)
