I started to learn symfony2 after I used symfony 1.4. I use the jobeet tutorial for symfony 2.3. I'm at day 6 where I should add an expired job with fixtures. I'm totally screwed up. I follow every single letter of the tutorial but can't get it work. When running php app/console doctrine:fixtures:load
I get the following error `
[PDOException] SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'Programming' for key 'UNIQ_64C19C15E237E06'
At the comments I don't see any comment about the error I get. There 2 jobs now. A programming category and a design category. When I try to add another job with programming category, it gives me an error. I know what is the error with the query, I just don't understand why it wants to do the query that way. I figured out that the problem is caused by the second job with programming category. I have the LoadCategoryData.php:
class LoadCategoryData extends AbstractFixture implements OrderedFixtureInterface{
public function load(ObjectManager $em){
$design = new Category();
$design->setName('Design');
$programming = new Category();
$programming->setName('Programming');
$manager = new Category();
$manager->setName('Manager');
$administrator = new Category();
$administrator->setName('Administrator');
$em->persist($design);
$em->persist($programming);
$em->persist($manager);
$em->persist($administrator);
$this->addReference('category-design', $design);
$this->addReference('category-programming', $programming);
$this->addReference('category-manager', $manager);
$this->addReference('category-administrator', $administrator);
}
public function getOrder(){
return 1;
}
}
And the LoadJobData.php(I will only show the 2 with the programming category):
//...
$job_expired->setCategory($em->merge($this->getReference('category-programming')));
//...
$job_sensio_labs->setCategory($em->merge($this->getReference('category-programming')));
//...
$em->persist($job_expired);
$em->persist($job_sensio_labs);
$em->flush();
My Category.orm.yml looks like this:
Ibw\JobeetBundle\Entity\Category:
type: entity
table: category
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
name:
type: string
length: 255
unique: true
oneToMany:
jobs:
targetEntity: Job
mappedBy: category
manyToMany:
affiliates:
targetEntity: Affiliate
mappedBy: categories
And the Job.orm.yml where I set the foreign key:
manyToOne:
category:
targetEntity: Category
inversedBy: jobs
joinColumn:
name: category_id
referencedColumnName: id
I could figure out that the error is caused by the line in the LoadJobData.php where I would set the category but I'm too new to symfony2 and can't find any solution for this. Thanks in advance and sorry for the long post.
unique
field do you have in you table?orm.yml
as well. Other than that? Are you sure that fixture data isunique
?$em->merge
method