[英]Table already exists,but it doesn't
我正在嘗試實現多對多關系以實現授權模塊。正如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.
但是我的數據庫沒有角色表。 我不知道什么導致了這個錯誤?有任何想法如何解決這個問題?非常感謝提前。
可能你需要改變這一行:
<join-table name="role">
至
<join-table name="users2role">
這是一個連接表 - 關系中的第三個表。
嘗試重命名為roles
:
<entity name="Office\DigitxpBundle\Entity\Role" table="roles">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.