# 表 'users' 已为此 MetaData 实例定义。请指定 'extend_existing=True' 以重新定义现有 Table 对象的选项和列。

- **ID:** `python/sqlalchemy-missing-schema-qualified-table`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在同一个 MetaData 中多次定义同名 Table，通常由模型导入或测试中重复使用元数据引起。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   # models.py
from sqlalchemy import MetaData, Table, Column, Integer
metadata = MetaData()
users = Table('users', metadata, Column('id', Integer), extend_existing=True)
# import only once via from models import metadata
   ```
2. **** (85% 成功率)
   ```
   from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class User(Base):
    __tablename__ = 'users'
    id = Column(Integer, primary_key=True)
   ```

## 无效尝试

- **** — Hides the root cause (duplicate definitions) and can lead to inconsistent schemas if columns differ. (40% 失败率)
- **** — Breaks relationships between models if they share a MetaData; causes new errors in foreign key resolution. (70% 失败率)
