Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLI Doctrine 2 - index already defined

I'm trying to create my database with Doctrine 2 from my PHP entity.

Here is my code from the class Team :

<?php
// Team.php
/**
 * @Entity @Table(name="team")
 **/
class Team
{
    /**
     * @Id
     * @OneToOne(targetEntity="User")
     * @JoinColumn(name="userID", referencedColumnName="id")
     */
    protected $user;

    /**
     * @Column(type="string",length=30)
     * @var string
     **/
    protected $function;

    /**
     * @Column(type="text")
     * @var string
     **/
    protected $description;

    /**
     * @OneToOne(targetEntity="File")
     * @JoinColumn(name="fileID", referencedColumnName="id")
     */
    protected $img;

    /**
     * @OneToOne(targetEntity="File")
     * @JoinColumn(name="fileID", referencedColumnName="id")
     */
    protected $cv;

    /**
     * @Id
     * @OneToOne(targetEntity="Language")
     * @JoinColumn(name="languageID", referencedColumnName="id")
     */
    protected $lang;

    public function getUser()
    {
        return $this->user;
    }

    public function setUser(User $user)
    {
        $this->user = $user;
    }

    public function getFunction()
    {
        return $this->function;
    }

    public function setFunction($function)
    {
        $this->function = $function;
    }

    public function getDescription()
    {
        return $this->description;
    }

    public function setDescription($description)
    {
        $this->description = $description;
    }

    public function getImg()
    {
        return $this->img;
    }

    public function setImg($img)
    {
        $this->img = $img;
    }

    public function getCv()
    {
        return $this->cv;
    }

    public function setCv($cv)
    {
        $this->cv = $cv;
    }

    public function getLang()
    {
        return $this->lang;
    }

    public function setLang(Language $language)
    {
        $this->lang = $language;
    }
}

And the error :

[Doctrine\DBAL\Schema\SchemaException]
An index with name 'uniq_c4e0a61f93cb796c' was already defined on table 'team'

Doctrine is loaded from composer and used with Windows CMD (if that can help).

I've seen that an issue has been reported for v.2.5.0 so I loaded 2.4.7 but same error, so I tried dev-master but still the same.

I also tried removing the composite Id and replaced it by a simple generated @Id, or even none (Doctrine was then saying No identifier/primary key specified for Entity "Team").

This code was working with v.2.4.2 but the point is to update the tools used for this project.

Do somebody know how I could do this ?

like image 604
TheDeveloo Avatar asked Feb 09 '23 12:02

TheDeveloo


1 Answers

Well well, I found the problem :

/**
 * @OneToOne(targetEntity="File")
 * @JoinColumn(name="fileID", referencedColumnName="id")
 */
protected $img;

/**
 * @OneToOne(targetEntity="File")
 * @JoinColumn(name="fileID", referencedColumnName="id")
 */
protected $cv;

More precisely @JoinColumn(name="fileID", referencedColumnName="id"), the column name fileID is the same for both.

Thanks anyway !

like image 164
TheDeveloo Avatar answered Feb 12 '23 02:02

TheDeveloo