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 ?
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 !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With