2015-11-25 74 views
2

我有以下實體類別在YML中定義,具有雙向多對多關係。當我嘗試通過doctrine:fixtures:load加載在相應的數據庫中的數據燈具我收到PDO異常錯誤1048約完整性違反了「名稱」字段不能爲空Doctrine2 PDO異常完整性違規1048 - 燈具加載 - YML

# 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) { 
 
\t $this - > slug = $slug; 
 

 
\t return $this; 
 
} 
 

 
/** 
 
* Get slug 
 
* 
 
* @return string 
 
*/ 
 
public 
 
function getSlug() { 
 
\t return $this - > slug; 
 
} 
 
/** 
 
* @ORM\PrePersist 
 
* @ORM\PreUpdate 
 
*/ 
 
public 
 
function setSlugValue() { 
 
\t $sl = new Slugify(); 
 
\t $this - > slug = $sl - > slugify($this - > getName()); 
 
} 
 

 
/** 
 
* @ORM\PrePersist 
 
* @ORM\PreUpdate 
 
*/ 
 
public 
 
function prePersist() { 
 
\t $this - > slug = ''; 
 
}
願你能燈具 here

+0

我們可能會看到您的固定裝置(S)? – scoolnico

+0

更新了與燈具鏈接的問題。 –

回答

0

你有20行一個錯字$qualityManager對象:

這裏:

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

試試這個:

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

希望這有助於

+1

謝謝!不能相信這個錯字給了我這樣的麻煩...... grrrrr –

相關問題