【问题标题】:Doctrine ManyToMany Relation 'The table with name already existsDoctrine ManyToMany Relation '同名的表已经存在
【发布时间】:2018-02-08 13:27:56
【问题描述】:

我有实体派对。很快它看起来像这样:

     AppBundle\Entity\Main\Party:
        type: entity
        table: main.party
        id:
            id:
                type: integer
                nullable: false
                id: true
                generator:
                    strategy: IDENTITY
        fields:
            legalName:
                type: string
                nullable: false
                length: 255
                options:
                    fixed: false
                column: legal_name
    manyToMany:
        partiesForPartner:
            targetEntity: AppBundle\Entity\Main\Party
            mappedBy: partnersForParty
            fetch: EXTRA_LAZY
            cache:
                usage: NONSTRICT_READ_WRITE
        partnersForParty:
            cascade: ["all"]
            targetEntity: AppBundle\Entity\Main\Party
            inversedBy: partiesForPartner
            fetch: LAZY
            joinTable:
                name: main.party_partnership
                joinColumns:
                    party_id:
                        referencedColumnName: id
                inverseJoinColumns:
                    partner_id:
                        referencedColumnName: id

还有一个实体PartnerPartnership。其中包括一些额外的道具。

AppBundle\Entity\Main\PartyPartnership:
    type: entity
    repositoryClass: AppBundle\Repository\Main\PartyPartnershipRepository
    table: main.party_partnership
    uniqueConstraints:
        party_partnership_ukey:
            columns:
                - party_id
                - partner_id
    id:
        id:
            type: integer
            nullable: false
            options:
                unsigned: false
            id: true
            generator:
                strategy: IDENTITY
    fields:
        codePartyByPartner:
            type: string
            nullable: true
            length: 35
            options:
                fixed: false
            column: code_party_by_partner
        codePartnerByParty:
            type: string
            nullable: true
            length: 35
            options:
                fixed: false
            column: code_partner_by_party
    manyToOne:
        party:
            targetEntity: AppBundle\Entity\Main\Party
            cascade: {  }
            fetch: LAZY
            mappedBy: null
            inversedBy: null
            joinColumns:
                party_id:
                    referencedColumnName: id
            orphanRemoval: false
        partner:
            targetEntity: AppBundle\Entity\Main\Party
            cascade: {  }
            fetch: LAZY
            mappedBy: null
            inversedBy: null
            joinColumns:
                partner_id:
                    referencedColumnName: id
            orphanRemoval: false
    lifecycleCallbacks: {  }

除了 Party 中的多对多关联之外,所有这些映射都是从 DB 导入的。现在,当我尝试启动诸如“doctrine:schema:validate”或“doctrine:schema:update”之类的学说命令时。我收到错误消息“名称为 'main.party_partnership' 的表已存在。”

【问题讨论】:

    标签: symfony doctrine-orm orm doctrine many-to-many


    【解决方案1】:

    Symfony ManyToMany 在两个链接的实体之间创建一个表。 这意味着它会在partypartnership之间自动创建表main.party_partnership

    Party        ---(ManyToMany main.party_partnership)---> Partnership
    

    您只需引用oneToMany,并删除manyToMany

    Party        ---(OneToMany)---> PartyPartnership
    Partnership  ---(OneToMany)---> PartyPartnership
    

    【讨论】:

    • 确实如此。表“main.party_partnership”包含“party”与附加属性之间的关系。我确信连接的错误定义中的错误是多对多的。但我不知道如何解决它
    【解决方案2】:

    几个小时后对我有用的是:清除缓存。

    【讨论】:

      猜你喜欢
      • 2023-03-10
      • 1970-01-01
      • 2017-07-21
      • 2017-04-04
      • 1970-01-01
      • 2021-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多