2017-11-02 23 views
1

Doctrine에는 초보자입니다.하지만 이렇게하면 이상한 오류가 발생합니다.doctrine : schema : update는 테이블을 찾지 만 업데이트하지 않습니다.

의 PHP 응용 프로그램/콘솔 교리 : 스키마 업데이트를 --dump-SQL

[Doctrine\DBAL\Schema\SchemaException]         
    The table with name 'akeneo_db01.pim_catalog_family' already exists. 

이것은 우리가 자원의 교리 디렉토리에 가지고 코드입니다.

Iclei\Bundle\BackendBundle\Entity\Family: 
type: entity 
table: pim_catalog_family 
changeTrackingPolicy: DEFERRED_EXPLICIT 
repositoryClass: Akeneo\Bundle\ClassificationBundle\Doctrine\ORM\Repository\CategoryRepository 
uniqueConstraints: 
    pim_category_code_uc: 
     columns: 
      - code 
fields: 
    templateCode: 
     type: text 
     nullable: true 

당신은 내가 pim_catalog_family에 필드 templateCode를 추가하려고하고 certanly 난 그냥 평범한 getter 및 setter 내가 잘못 뭐하는 거지

와 엔티티 디렉토리에있어 볼 수 있듯이?

편집 :이

<?php 
/** 
* Created by PhpStorm. 
* User: nebo 
* Date: 2.11.17. 
* Time: 10.50 
*/ 

namespace Iclei\Bundle\BackendBundle\Entity; 

use Pim\Bundle\CatalogBundle\Entity\Family as BaseFamily; 

class Family extends BaseFamily 
{ 
    protected $templateCode; 

    /** 
    * @return mixed 
    */ 
    public function getTemplateCode() 
    { 
     return $this->templateCode; 
    } 

    /** 
    * @param mixed $templateCode 
    */ 
    public function setTemplateCode($templateCode) 
    { 
     $this->templateCode = $templateCode; 
    } 
} 

우리 Family.php 법인

입니다 그리고 이것은 내가 업데이트하려고 무엇을 :

<?php 

namespace Pim\Bundle\CatalogBundle\Entity; 

use Akeneo\Component\Localization\Model\TranslationInterface; 
use Doctrine\Common\Collections\ArrayCollection; 
use Pim\Component\Catalog\AttributeTypes; 
use Pim\Component\Catalog\Model\AttributeInterface; 
use Pim\Component\Catalog\Model\AttributeRequirementInterface; 
use Pim\Component\Catalog\Model\FamilyInterface; 

/** 
* Family entity 
* 
* @author Filips Alpe <[email protected]> 
* @copyright 2013 Akeneo SAS (http://www.akeneo.com) 
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 
*/ 
class Family implements FamilyInterface 
{ 
    /** 
    * @var int 
    */ 
    protected $id; 

    /** 
    * @var string 
    */ 
    protected $code; 

    /** 
    * @var \Doctrine\Common\Collections\ArrayCollection 
    */ 
    protected $attributes; 

    /** 
    * Used locale to override Translation listener's locale 
    * this is not a mapped field of entity metadata, just a simple property 
    * 
    * @var string 
    */ 
    protected $locale; 

    /** 
    * @var \Doctrine\Common\Collections\ArrayCollection 
    */ 
    protected $translations; 

    /** 
    * @var AttributeInterface 
    */ 
    protected $attributeAsLabel; 

    /** 
    * @var \Doctrine\Common\Collections\ArrayCollection 
    */ 
    protected $requirements; 

    /** 
    * @var \DateTime 
    */ 
    protected $created; 

    /** 
    * @var \DateTime 
    */ 
    protected $updated; 

    /** 
    * Constructor 
    */ 
    public function __construct() 
    { 
     $this->attributes = new ArrayCollection(); 
     $this->translations = new ArrayCollection(); 
     $this->requirements = new ArrayCollection(); 
    } 

    /** 
    * Returns the label of the family 
    * 
    * @return string 
    */ 
    public function __toString() 
    { 
     return $this->getLabel(); 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function getId() 
    { 
     return $this->id; 
    } 

    /** 
    * Get created datetime 
    * 
    * @return \DateTime 
    */ 
    public function getCreated() 
    { 
     return $this->created; 
    } 

    /** 
    * Set created datetime 
    * 
    * @param \DateTime $created 
    * 
    * @return Family 
    */ 
    public function setCreated($created) 
    { 
     $this->created = $created; 

     return $this; 
    } 

    /** 
    * Get updated datetime 
    * 
    * @return \DateTime 
    */ 
    public function getUpdated() 
    { 
     return $this->updated; 
    } 

    /** 
    * Set updated datetime 
    * 
    * @param \DateTime $updated 
    * 
    * @return Family 
    */ 
    public function setUpdated($updated) 
    { 
     $this->updated = $updated; 

     return $this; 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function getCode() 
    { 
     return $this->code; 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function setCode($code) 
    { 
     $this->code = $code; 

     return $this; 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function addAttribute(AttributeInterface $attribute) 
    { 
     if (!$this->attributes->contains($attribute)) { 
      $this->attributes->add($attribute); 
     } 

     return $this; 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function removeAttribute(AttributeInterface $attribute) 
    { 
     if (AttributeTypes::IDENTIFIER === $attribute->getType()) { 
      throw new \InvalidArgumentException('Identifier cannot be removed from a family.'); 
     } 

     $this->attributes->removeElement($attribute); 

     return $this; 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function getAttributes() 
    { 
     return $this->attributes; 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function getAttributeCodes() 
    { 
     $codes = []; 
     foreach ($this->attributes as $attribute) { 
      $codes[] = $attribute->getCode(); 
     } 

     return $codes; 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function getGroupedAttributes() 
    { 
     $result = []; 
     foreach ($this->attributes as $attribute) { 
      $result[(string) $attribute->getGroup()][] = $attribute; 
     } 

     return $result; 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function hasAttribute(AttributeInterface $attribute) 
    { 
     return $this->attributes->contains($attribute); 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function hasAttributeCode($attributeCode) 
    { 
     return in_array($attributeCode, $this->getAttributeCodes()); 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function setAttributeAsLabel(AttributeInterface $attributeAsLabel) 
    { 
     $this->attributeAsLabel = $attributeAsLabel; 

     return $this; 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function getAttributeAsLabel() 
    { 
     return $this->attributeAsLabel; 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function getAttributeAsLabelChoices() 
    { 
     return $this->attributes->filter(
      function ($attribute) { 
       return in_array(
        $attribute->getType(), 
        [AttributeTypes::TEXT, AttributeTypes::IDENTIFIER] 
       ); 
      } 
     )->toArray(); 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function setLocale($locale) 
    { 
     $this->locale = $locale; 

     return $this; 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function getTranslations() 
    { 
     return $this->translations; 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function getTranslation($locale = null) 
    { 
     $locale = ($locale) ? $locale : $this->locale; 
     if (null === $locale) { 
      return null; 
     } 
     foreach ($this->getTranslations() as $translation) { 
      if ($translation->getLocale() == $locale) { 
       return $translation; 
      } 
     } 

     $translationClass = $this->getTranslationFQCN(); 
     $translation = new $translationClass(); 
     $translation->setLocale($locale); 
     $translation->setForeignKey($this); 
     $this->addTranslation($translation); 

     return $translation; 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function addTranslation(TranslationInterface $translation) 
    { 
     if (!$this->translations->contains($translation)) { 
      $this->translations->add($translation); 
     } 

     return $this; 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function removeTranslation(TranslationInterface $translation) 
    { 
     $this->translations->removeElement($translation); 

     return $this; 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function getTranslationFQCN() 
    { 
     return 'Pim\Bundle\CatalogBundle\Entity\FamilyTranslation'; 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function getLabel() 
    { 
     $translated = $this->getTranslation() ? $this->getTranslation()->getLabel() : null; 

     return ($translated !== '' && $translated !== null) ? $translated : '['.$this->getCode().']'; 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function setLabel($label) 
    { 
     $this->getTranslation()->setLabel($label); 

     return $this; 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function addAttributeRequirement(AttributeRequirementInterface $requirement) 
    { 
     $requirementKey = $this->getAttributeRequirementKey($requirement); 
     $requirements = $this->getAttributeRequirements(); 

     if (!isset($requirements[$requirementKey])) { 
      $requirement->setFamily($this); 
      $this->requirements->add($requirement); 
     } else { 
      $requirements[$requirementKey]->setRequired($requirement->isRequired()); 
     } 

     return $this; 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function removeAttributeRequirement(AttributeRequirementInterface $requirement) 
    { 
     $this->requirements->removeElement($requirement); 

     return $this; 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function setAttributeRequirements(array $requirements) 
    { 
     foreach ($requirements as $requirement) { 
      $requirement->setFamily($this); 
     } 
     $this->requirements = new ArrayCollection($requirements); 

     return $this; 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function getAttributeRequirements() 
    { 
     $result = []; 

     foreach ($this->requirements as $requirement) { 
      $key = $this->getAttributeRequirementKey($requirement); 
      $result[$key] = $requirement; 
     } 

     return $result; 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function getAttributeRequirementKey(AttributeRequirementInterface $requirement) 
    { 
     return sprintf(
      '%s_%s', 
      $requirement->getAttributeCode(), 
      $requirement->getChannelCode() 
     ); 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function getReference() 
    { 
     return $this->code; 
    } 
} 

답변

0

uniqueConstraints 정의는 존재하지 않는 code 필드가 포함되어 있습니다. templateCode

+0

도움 주셔서 감사합니다. 아샤,하지만 저는 확신하지 못합니다. 코드 필드는 Pim \ Bundle | CatalogBundle \ Entity \ Family에 있습니다. 매핑 파일에 – FortuneSoldier

+0

이 있습니까? 전체 매핑 파일을 넣을 수 있습니까? 때로는 잘못 정의 된 관계 때문이기도합니다. – Asha

+0

나는 질문을 편집했다. – FortuneSoldier

1

이것은 Symfony의 구성 (app/config/config.yml) 파일에 추가해야하기 때문에 발생했습니다.

akeneo_storage_utils: 
    mapping_overrides: 
      - 
      original: Pim\Bundle\CatalogBundle\Entity\Family 
      override: Iclei\Bundle\BackendBundle\Entity\Family