# Doctrine\ORM\Mapping\MappingException：在实体 'App\Entity\Order' 中检测到重复的列定义 'created_at'

- **ID:** `php/symfony-doctrine-mapping-duplicate-column`
- **领域:** php
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

一个 Doctrine 实体有两个或多个属性映射到同一个数据库列名，通常是由于继承映射冲突或注解/属性中的复制粘贴错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Doctrine ORM 2.14 | active | — | — |
| Doctrine ORM 2.15 | active | — | — |
| Doctrine ORM 3.0 | active | — | — |

## 解决方案

1. ```
   Inspect the entity and its parent classes for duplicate column definitions. Run `php bin/console doctrine:mapping:info` to list all mapped fields. Then check each property's column attribute: e.g., `#[ORM\Column(name: 'created_at')]` should appear only once. Rename one property's column to something else like 'created_at_utc'.
   ```
2. ```
   If using inheritance (e.g., MappedSuperclass), ensure the child class does not override a column from the parent. Use `@ORM\AttributeOverride` to explicitly rename columns in the child: `#[ORM\AttributeOverrides([new ORM\AttributeOverride(name: 'createdAt', column: new ORM\Column(name: 'order_created_at'))])]`
   ```

## 无效尝试

- **Clearing Doctrine metadata cache with `php bin/console doctrine:cache:clear-metadata`** — The error is in the mapping definition itself, not in a stale cache; clearing cache will not fix duplicate column definitions. (90% 失败率)
- **Removing all properties that reference 'created_at' from the entity** — This might remove needed functionality; the correct approach is to rename one of the properties or use a different column name. (50% 失败率)
