删除实体属性后 Doctrine ORM 缓存错误

问题描述 投票:0回答:1

我已从我的

id
中删除了列/属性
Entity
,我认为存在一些缓存问题,导致在尝试访问
Entity
时出现以下错误:

Uncaught ReflectionException: Given object is not an instance of the class this property was declared in in [...]/vendor/doctrine/persistence/src/Persistence/Reflection/TypedNoDefaultReflectionPropertyBase.php:33
Stack trace:
#0 .../vendor/doctrine/persistence/src/Persistence/Reflection/TypedNoDefaultReflectionPropertyBase.php(33): ReflectionProperty->isInitialized(Object(Project\Entities\Entity))
#1 .../vendor/doctrine/orm/src/UnitOfWork.php(586): Doctrine\Persistence\Reflection\TypedNoDefaultReflectionProperty->getValue(Object(Project\Entities\Entity))
...
Creation of dynamic property Project\Entities\Entity::$id is deprecated;
.../vendor/doctrine/persistence/src/Persistence/Reflection/RuntimeReflectionProperty.php; 60

我已经运行了

php config/cli-config.php orm:generate-proxies
(成功生成了新代理),但是当尝试以下任何操作来清除缓存时:

  1. php config/cli-config.php orm:clear-cache:query
  2. php config/cli-config.php orm:clear-cache:metadata
  3. php config/cli-config.php orm:clear-cache:result

我收到这样的错误:

In MemcachedAdapter.php line 300:
                                                     
  MemcachedAdapter client error: connection failure  
                                                     

“修补程序”是将

isDevMode
参数更改为
true

return new EntityManager(
    DriverManager::getConnection($params),
    ORMSetup::createAttributeMetadataConfiguration(
        paths: [__DIR__ . '/../Entities'],
        isDevMode: true, // :(
        proxyDir: __DIR__ . '/../../../tmp',
    ),
);

请帮助我正确修复这些错误。我不知道接下来要做什么/检查。

运行于:

  1. PHP 8.2
  2. 学说 ORM 3.1.0
  3. 学说 DBAL 4.0.1
  4. Symfony 缓存 7.0.4

cli-config.php
基本上是:

ConsoleRunner::run(new SingleManagerProvider($entity_manager));

澄清一下:

我已经改变了这个:

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

对此:

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

SHOW CREATE TABLE entity;
给出:

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
php caching orm doctrine-orm doctrine
1个回答
0
投票

原来是因为

apcu cache
哪个

只能由网络服务器访问。

并且在

php.ini
apc
被 CLI 禁用,解释了为什么
orm:clear-cache
默认为
MemcachedAdapter

apc.enable_cli=0

启用它并没有帮助,因为它们是网络服务器和 CLI 的不同缓存,因此我需要使用例如在网络服务器中触发

apcu_clear_cache()
curl
到特定(安全)脚本

© www.soinside.com 2019 - 2024. All rights reserved.