php
config_error
ai_generated
true
Doctrine\ORM\Mapping\MappingException: Duplicate column definition 'created_at' detected in entity 'App\Entity\Order'
ID: php/symfony-doctrine-mapping-duplicate-column
90%Fix Rate
85%Confidence
1Evidence
2024-05-02First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| Doctrine ORM 2.14 | active | — | — | — |
| Doctrine ORM 2.15 | active | — | — | — |
| Doctrine ORM 3.0 | active | — | — | — |
Root Cause
A Doctrine entity has two or more properties mapped to the same database column name, often due to inheritance mapping conflicts or copy-paste errors in annotations/attributes.
generic中文
一个 Doctrine 实体有两个或多个属性映射到同一个数据库列名,通常是由于继承映射冲突或注解/属性中的复制粘贴错误。
Official Documentation
https://www.doctrine-project.org/projects/doctrine-orm/en/2.14/reference/inheritance-mapping.htmlWorkarounds
-
90% success 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'.
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'.
-
80% success 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'))])]`
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'))])]`
中文步骤
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'.
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'))])]`
Dead Ends
Common approaches that don't work:
-
Clearing Doctrine metadata cache with `php bin/console doctrine:cache:clear-metadata`
90% fail
The error is in the mapping definition itself, not in a stale cache; clearing cache will not fix duplicate column definitions.
-
Removing all properties that reference 'created_at' from the entity
50% fail
This might remove needed functionality; the correct approach is to rename one of the properties or use a different column name.