I've the following entity Category defined in YML with bi-directional many-to-many relationship. When i try to load the fixtures data in the corresponding database via doctrine:fixtures:load
i receive a PDO Exception error 1048 about integrity violation that the 'name' field can't be null
# src/tuto/JobeetBundle/Resources/config/doctrine/Category.orm.yml
tuto\JobeetBundle\Entity\Category:
type: entity
repositoryClass: tuto\JobeetBundle\Repository\CategoryRepository
table: category
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
name:
type: string
length: 255
unique: true
slug:
type: string
length: 255
unique: true
oneToMany:
jobs:
targetEntity: Job
mappedBy: category
manyToMany:
affiliates:
targetEntity: Affiliate
mappedBy: categories
lifecycleCallbacks:
prePersist: [setSlugValue]
preUpdate: [setSlugValue]
/**
* @var string
*/
private $slug;
public
function setSlug($slug) {
$this - > slug = $slug;
return $this;
}
/**
* Get slug
*
* @return string
*/
public
function getSlug() {
return $this - > slug;
}
/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public
function setSlugValue() {
$sl = new Slugify();
$this - > slug = $sl - > slugify($this - > getName());
}
/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public
function prePersist() {
$this - > slug = '';
}
You have a typo $qualityManager
object on line 20:
Here:
$qualityManager = new Category();
$technician->setName("Quality Manager"); // <-- Wrong object
Try this:
$qualityManager = new Category();
$qualityManager->setName("Quality Manager");
Hope this help