# 实例 <Child at 0x...> 具有 NULL 标识键。如果这是自动生成的值，请检查数据库表是否允许生成新的主键值，以及映射的 Column 对象配置是否正确。

- **ID:** `python/sqlalchemy-relationship-delete-orphan-without-cascade`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

试图删除未正确关联或缺少主键的子对象，通常由于缺少 cascade delete-orphan。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   class Parent(Base):
    children = relationship('Child', cascade='all, delete-orphan')
# Then remove child: parent.children.remove(child)
   ```
2. **** (80% 成功率)
   ```
   session.delete(child)
session.commit()
   ```

## 无效尝试

- **** — May conflict with auto-increment; not scalable. (50% 失败率)
- **** — The child still exists in session and gets flushed. (70% 失败率)
