0

我的实体类:

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
4

2 回答 2

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
{
于 2020-10-10T10:09:15.273 回答
0

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

@ORM\Table(name="customers")通过在下面插入uniqueConstraints,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
{
于 2020-10-09T04:55:57.867 回答