You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

移除Entity属性后Doctrine ORM缓存错误求助

问题与修复方案请求

问题现象

将Entity实体的id属性移除,改为关联Base实体后,访问该Entity时出现两类缓存相关错误:

  • 反射异常:提示对象不属于属性声明类
  • PHP 8.2动态属性创建废弃警告

已尝试操作

  1. 执行php config/cli-config.php orm:generate-proxies成功生成新代理类
  2. 尝试清理Doctrine缓存时,执行以下命令均报错Memcached连接失败:
    • orm:clear-cache:query
    • orm:clear-cache:metadata
    • orm:clear-cache:result

临时解决方案

将ORM配置中的isDevMode设为true,暂时规避了错误,但需要找到正式修复方案。

运行环境

  • PHP 8.2
  • Doctrine ORM 3.1.0
  • Doctrine DBAL 4.0.1
  • Symfony cache 7.0.4

实体与数据库修改细节

原Entity实体代码

#[Id]
#[Column(name: 'id', type: Types::INTEGER, updatable: false, options: ['unsigned' => true])]
#[GeneratedValue]
private int $id;

修改后Entity实体代码

#[Id]
#[OneToOne(targetEntity: Base::class, inversedBy: 'entity')]
#[JoinColumn(name: 'id', referencedColumnName: 'id', unique: true)]
private Base $base;

对应数据库表结构

CREATE TABLE `entity` (
  `id` int unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `entity_base_fk` (`id`),
  CONSTRAINT `entity_base_fk` FOREIGN KEY (`id`) REFERENCES `base` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci

内容的提问来源于stack exchange,提问作者Unlucky

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 15:55:56