我在YML中定义了以下实体类别,具有双向多对多关系。当我尝试通过doctrine:fixtures:load
在相应的数据库中加载灯具数据时,我收到关于完整性违规的 PDO异常错误1048 ,即“名称”字段不能为空
# 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 = '';
}
答案 0 :(得分:0)
第20行有一个拼写错误$qualityManager
对象:
下面:
$qualityManager = new Category();
$technician->setName("Quality Manager"); // <-- Wrong object
试试这个:
$qualityManager = new Category();
$qualityManager->setName("Quality Manager");
希望这个帮助