Zend/Doctrine 无法执行 ORM 操作,table 已经存在
Zend/Doctrine can't perform ORM operations, table already exists
我从另一个团队继承了一个项目,但似乎无法对数据库做任何事情。我是 zend 和 doctrine 的新手,但 ORM 工具似乎足够简单;但是,当尝试使用它时,我从 orm:schema-tool:drop
、orm:schema-tool:create
、orm:schema-tool:update
等
得到了相同的错误
[Doctrine\DBAL\Schema\SchemaException]
The table with name 'mydb.alerts_residents' already exists.
我的数据库已创建,但没有 table。我读过的其他帖子让我得出结论,这条消息是基于我的实体对象定义和注释。
您可能会怀疑,alerts_residents
是一个连接 table,它将 Alert
实体与 Resident
实体以多对多关系连接起来。这些是唯一引用此 table 的实体,而且它们似乎正确地引用了此内容。
class Resident
{
/**
* @var ArrayCollection $zone
*
* @ORM\ManyToMany(targetEntity="Alert")
* @ORM\JoinTable(
* name="alerts_residents",
* joinColumns={@ORM\JoinColumn(name="resident_id", referencedColumnName="id", onDelete="CASCADE")},
* inverseJoinColumns={@ORM\JoinColumn(name="alert_id", referencedColumnName="id", onDelete="CASCADE")}
* )
*/
protected $alerts;
class Alert
{
/**
* @var ArrayCollection $zone
*
* @ORM\ManyToMany(targetEntity="Resident")
* @ORM\JoinTable(
* name="alerts_residents",
* joinColumns={@ORM\JoinColumn(name="alert_id", referencedColumnName="id", onDelete="CASCADE")},
* inverseJoinColumns={@ORM\JoinColumn(name="resident_id", referencedColumnName="id", onDelete="CASCADE")}
* )
*/
protected $residents;
没有 @ORM\Table(name="alerts_residents")
的实体。为什么会出现此错误?
您已经冗余地定义了多对多。 M2M 关联有点奇怪,因为连接 table 没有自己的实体。因此,一方(或多或少)被任意选择为拥有方,即获得加入 table 详细信息的实体。您的示例在两者上都有 @ORM\JoinTable
注释。
我从另一个团队继承了一个项目,但似乎无法对数据库做任何事情。我是 zend 和 doctrine 的新手,但 ORM 工具似乎足够简单;但是,当尝试使用它时,我从 orm:schema-tool:drop
、orm:schema-tool:create
、orm:schema-tool:update
等
[Doctrine\DBAL\Schema\SchemaException]
The table with name 'mydb.alerts_residents' already exists.
我的数据库已创建,但没有 table。我读过的其他帖子让我得出结论,这条消息是基于我的实体对象定义和注释。
您可能会怀疑,alerts_residents
是一个连接 table,它将 Alert
实体与 Resident
实体以多对多关系连接起来。这些是唯一引用此 table 的实体,而且它们似乎正确地引用了此内容。
class Resident
{
/**
* @var ArrayCollection $zone
*
* @ORM\ManyToMany(targetEntity="Alert")
* @ORM\JoinTable(
* name="alerts_residents",
* joinColumns={@ORM\JoinColumn(name="resident_id", referencedColumnName="id", onDelete="CASCADE")},
* inverseJoinColumns={@ORM\JoinColumn(name="alert_id", referencedColumnName="id", onDelete="CASCADE")}
* )
*/
protected $alerts;
class Alert
{
/**
* @var ArrayCollection $zone
*
* @ORM\ManyToMany(targetEntity="Resident")
* @ORM\JoinTable(
* name="alerts_residents",
* joinColumns={@ORM\JoinColumn(name="alert_id", referencedColumnName="id", onDelete="CASCADE")},
* inverseJoinColumns={@ORM\JoinColumn(name="resident_id", referencedColumnName="id", onDelete="CASCADE")}
* )
*/
protected $residents;
没有 @ORM\Table(name="alerts_residents")
的实体。为什么会出现此错误?
您已经冗余地定义了多对多。 M2M 关联有点奇怪,因为连接 table 没有自己的实体。因此,一方(或多或少)被任意选择为拥有方,即获得加入 table 详细信息的实体。您的示例在两者上都有 @ORM\JoinTable
注释。