Doctrine many-to-many relationship wants to create a table twice when I create a migration

后端 未结 1 494
长情又很酷
长情又很酷 2021-02-08 08:43

Before I describe my problem, it might actually make it clearer if I start with the error I\'m getting:

$ ./app/console doc:mig:diff

  [Doctrine\\DBAL\\Schema\\         


        
相关标签:
1条回答
  • 2021-02-08 09:40

    According to the Association Mapping explanation on the official docs, the @JoinColumn and @JoinTable definitions are usually optional and have sensible default values, being:

    name: "<fieldname>_id"
    referencedColumnName: "id"
    

    From that we can conclude that there is really no concrete difference between the two implementations you presented.

    However, when it comes to migration, the creation of the table is a pretty common and expected behaviour. The thing is the table should always get deleted and created again, which is not happenning.

    About the table name issue, the default behaviour of Doctrine 2 about this:

    /**
     * @ORM\ManyToMany(targetEntity="MediaArea", inversedBy="mediaAreas")
     */
    private $mediaAreas;
    

    Is to try and create a table called mediaarea. Again, perfectly normal.

    If you want to declare a specific name for the table of an entity, you should do this:

    /**
     * @ORM\Table(name="my_table")
     */
    class Something
    

    I'm not sure if that helps you at all, but I guess it puts you, at least, on the right track.

    0 讨论(0)
提交回复
热议问题