Doctrine2 PDO异常完整性违规1048 - 夹具加载 - YML

时间:2015-11-25 10:14:46

标签: php symfony pdo doctrine-orm fixtures

我在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 = '';
}
你可以找到夹具here

1 个答案:

答案 0 :(得分:0)

第20行有一个拼写错误$qualityManager对象:

下面:

$qualityManager = new Category();
$technician->setName("Quality Manager");  // <-- Wrong object

试试这个:

$qualityManager = new Category();
$qualityManager->setName("Quality Manager");

希望这个帮助