表已经存在,但它没有

时间:2014-01-24 11:22:32

标签: php symfony

我正在尝试实现多对多的关系以实现授权模块。正如symfony所建议的那样,我正在尝试将两个表用户和角色用于多对多的实现。我已经编写了一个元数据文件,我正在尝试使用它来生成数据库模式。

以下是我的元数据文件。

VmsUsers.orm .xml

<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Office\DigitxpBundle\Entity\VmsUsers" table="vms_users" >

<id name="id" type="integer" column="id">
  <generator strategy="IDENTITY"/>
</id>
<field name="username" type="string" column="username" length="20" nullable="false"/>
<field name="salt" type="string" column="salt" length="20" nullable="true"/>
<field name="password" type="string" column="password" length="20" nullable="false"/>
<field name="email" type="string" column="email" length="20" nullable="false"/>
<field name="isActive" type="boolean" column="is_active" nullable="false"/>
<many-to-many field="userRoles" target-entity="Role">
            <cascade>
                <cascade-all/>
            </cascade>
            <join-table name="user_role">
                <join-columns>
                    <join-column name="roles" referenced-column-name="id" nullable="false" unique="false" />
                </join-columns>
                <inverse-join-columns>
                    <join-column name="user" referenced-column-name="id" column-definition="INT NULL" />
                </inverse-join-columns>
            </join-table>
    </many-to-many>
 </entity>
 </doctrine-mapping>

当我尝试运行时

  doctrine:schema:update --force

我喜欢

  [Doctrine\DBAL\Schema\SchemaException]           
  The table with name 'vms1.role' already exists.

但是我的数据库没有角色表。我不知道导致这个错误的原因是什么?知道如何解决这个问题吗?非常感谢提前。

2 个答案:

答案 0 :(得分:2)

您可能需要更改此行:

<join-table name="role">

<join-table name="users2role">

这是一个连接表 - 关系中的第三个表。

答案 1 :(得分:0)

尝试重命名为roles

<entity name="Office\DigitxpBundle\Entity\Role" table="roles">
相关问题