【问题标题】:Doctrine ORM\Table(name="name") not working教义 ORM\Table(name="name") 不起作用
【发布时间】:2020-10-08 01:03:26
【问题描述】:

我的实体类:

use Doctrine\ORM\Mapping as ORM;

/**
 * CustomerEntity
 * @ORM\Entity
 * @ORM\Table(name="customers")
 * @ORM\Table(uniqueConstraints={
 *   @ORM\UniqueConstraint(name="email", columns={"email"}),
 * })
 * @ORM\Entity(repositoryClass="Customer\V1\Rest\Customer\CustomerRepository")
 */
class CustomerEntity
{

但是当我添加一个客户时它会抛出这个错误,它正在寻找错误的表。

SQLSTATE[42S02]:未找到基表或视图:1146 表 'database.customerentity' 不存在

我确实尝试过,但没有帮助:

@ORM\Table(name="`customers`")

架构生成显示了这一点:

$ doctrine-module orm:schema-tool:update --dump-sql

 The following SQL statements will be executed:

 CREATE TABLE CustomerEntity (id VARCHAR(36) NOT NULL, 
 .....

我做错了什么?

我也清除了缓存

orm:clear-cache:metadata
orm:clear-cache:query
orm:clear-cache:result

【问题讨论】:

  • 你清除缓存了吗?
  • 我处于开发者模式。而data/cache 文件夹是空的。

标签: orm doctrine-orm laminas


【解决方案1】:

您遇到的问题是,Doctrine 只期望每个注释一次。试试这个:

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Table(name="customers", uniqueConstraints={
 *   @ORM\UniqueConstraint(name="email", columns={"email"}),
 * })
 * @ORM\Entity(repositoryClass="Customer\V1\Rest\Customer\CustomerRepository")
 */
class CustomerEntity
{

【讨论】:

    【解决方案2】:

    这真是令人沮丧,在浏览了 ORM 核心代码之后,我能够查明问题所在。没有时间进一步调查以验证错误或这是一项功能(正常行为)。

    通过在uniqueConstraints下方插入@ORM\Table(name="customers"),ORM就能够识别表名。

    use Doctrine\ORM\Mapping as ORM;
    
    /**
     * CustomerEntity
     * @ORM\Entity
     * @ORM\Table(uniqueConstraints={
     *   @ORM\UniqueConstraint(name="email", columns={"email"}),
     * })
     * @ORM\Table(name="customers")
     * @ORM\Entity(repositoryClass="Customer\V1\Rest\Customer\CustomerRepository")
     */
    class CustomerEntity
    {
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-28
      • 2017-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-08
      • 1970-01-01
      相关资源
      最近更新 更多