doctrine: schema: update находит таблицу, но не обновляет ее

Я новичок в доктрине, но у меня возникает странная ошибка, когда я это делаю.

php app / console доктрина: схема: обновление —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

Как вы можете видеть, я пытаюсь добавить поле templateCode в pim_catalog_family и, конечно, я получил его в каталоге Entity просто с помощью геттеров и сеттеров.

Что я делаю неправильно ?

Изменить: это наш объект Family.php

    <?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;
}
}

И вот что я пытаюсь обновить:

    <?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 <filips@akeneo.com>
* @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;
}
}

1

Решение

Это произошло потому, что мы должны добавить его в файл конфигурации (app / config / config.yml) в Symfony.

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

Другие решения

Определение uniqueConstraints содержит code поле, которое не существует. Измените это на templateCode

0