# django.db.utils.IntegrityError: NOT NULL constraint failed: auth_user.username

- **ID:** `python/django-auth-user-creation-error`
- **Domain:** python
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

创建用户时未提供用户名

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.2 | active | — | — |
| 4.0 | active | — | — |
| 5.0 | active | — | — |

## Workarounds

1. **在创建用户时提供用户名** (100% success)
   ```
   User.objects.create_user(username='john', email='john@example.com', password='pass')
   ```
2. **使用 create() 方法并确保提供所有必填字段** (95% success)
   ```
   user = User(username='john', email='john@example.com'); user.set_password('pass'); user.save()
   ```

## Dead Ends

- **设置 username 为 NULL** — 数据库约束不允许 NULL (100% fail)
- **使用 email 作为用户名** — 需要自定义用户模型 (50% fail)
