php - 引用的列名必须是目标实体类上的主键列

标签 php mysql linux doctrine-orm doctrine

大家。新年快乐!今天我在尝试解决这个问题时遇到了问题:

Could not resolve type of column "id_usuario" of class "FacturadorVirtual\Modelos\Seguridad\Usuario"

对于某些人来说,这个错误只存在于 linux 环境中。在Windows中,没问题。到底是什么问题?看起来 PlanAdquirido 没有通过关系 $adquiridoPor 找到列 id_usuario。再次声明:此错误仅在 linux 环境中触发。

Usuario 实体:

<?php

namespace FacturadorVirtual\Modelos\Seguridad;

use Illuminate\Contracts\Auth\Authenticatable;

/**
 * @entity
 * @table(name="usuarios")
 */
class Usuario implements Authenticatable
{
    /**
     * @id
     * @var integer
     * @column(type="integer", name="id_usuario")
     * @generatedValue(strategy="AUTO")
     */
    protected $id;
}

PlanAdquirido 实体:

<?php

namespace FacturadorVirtual\Modelos\Planes;

use Doctrine\Common\Collections\ArrayCollection;
use FacturadorVirtual\Modelos\Seguridad\Usuario;

/**
 * @entity
 * @table(name="planes_adquiridos")
 */
class PlanAdquirido
{
    /**
     * @id
     * @var integer
     * @column(type="integer", name="id_plan")
     * @GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @var Usuario
     * @ManyToOne(targetEntity="FacturadorVirtual\Modelos\Seguridad\Usuario")
     * @JoinColumn(name="adquirido_por", referencedColumnName="id_usuario")
     */
    protected $adquiridoPor;

}

如果我在 Windows 中运行 "vendor/bin/doctrine.bat"orm:validate-schema 我得到:

Mapping
-------
[OK] The mapping files are correct.

但是在 linux 中我得到:

Mapping
-------
 [FAIL] The entity-class FacturadorVirtual\Modelos\Planes\PlanAdquirido mapping is invalid:
 * The referenced column name 'id_plan' has to be a primary key column on the target entity class 'FacturadorVirtual\Modelos\Planes\PlanAdquirido'.
 * The referenced column name 'id_usuario' has to be a primary key column on the target entity class 'FacturadorVirtual\Modelos\Seguridad\Usuario'.

Column name id_usuario referenced for relation from FacturadorVirtual\Modelos\Planes\PlanAdquirido towards FacturadorVirtual\Modelos\Seguridad\Usuario does not exist.

我不知道我是否遗漏了什么,但我有两天的时间试图弄清楚为什么不能在 linux(生产所在的地方)工作。

  • 表名和列名全部小写,使用MySQL 5.7

最佳答案

今天我找到了答案。问题是 redi 的缓存。每次更新项目时,我都会运行清除缓存命令:

"vendor/bin/doctrine" orm:clear-cache:metadata

我以为这条命令已经清除了缓存,但并没有。要正确清除缓存,只需运行:

$ redis-cli
> flushall

从那以后一切都很好!

关于php - 引用的列名必须是目标实体类上的主键列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48065187/

相关文章:

php - Symfony Twig : Why use asset method?

php - PHP 中的 Europe/London 和 UTC 之间有区别吗?

javascript - 从数据 uri 将图像上传到服务器

php - 为什么 php 脚本在表中添加空白字段?

mysql - 返回 NULL 时在 GroupByMonth 中获取 0

mysql - 从连接表中减去时选择图书计数

php - 只有php查询的结果显示在html表中,其余显示在外面

c - fork 子进程不断被终止,状态为 0x008B

java - 无法执行shell脚本

linux - 是否可以在 docker 容器中运行 linux perf 工具