sylius中的覆盖Order类抛出异常'sylius_order'已经存在

时间:2018-09-07 07:00:28

标签: symfony sylius

我正在尝试向订单表添加一个新字段。但是覆盖抛出错误,就像表已经存在一样。我尝试关注https://github.com/Sylius/Sylius/issues/3997问题。但没有运气。

我的实体

   <?php

namespace Goldco\Entity;

use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Order\Model\Order as BaseOrder;//Sylius\Component\Core\Model\Order as BaseOrder;
use Sylius\Component\Order\Model\OrderItemUnitInterface;

/**
 * Order
 *
 * @ORM\Table(name="sylius_order")
 * @ORM\Entity
 */
class Order extends BaseOrder
{


    /**
     * @var string|null
     *
     * @ORM\Column(name="quantity_decimal", type="decimal", precision=12, scale=4, nullable=true, options={"comment"="decimal quantity"})
     */
    private $quantityDecimal;



}

配置文件:

sylius_order:
    resources:
        order_item:
            classes:
                model: Goldco\Entity\SyliusOrderItem
                controller : Goldco\Controller\App\OrderItemController
        order:
            classes:
                model: Goldco\Entity\Order
                controller: Sylius\Bundle\CoreBundle\Controller\OrderController
                repository: Sylius\Bundle\CoreBundle\Doctrine\ORM\OrderRepository

和orm.yml

Goldco\Entity\Order:
    type: entity
    table: sylius_order
    fields:
        quantityDecimal:
            type: decimal
            nullable: true
            precision: 12
            scale: 4
            options:
                comment: 'decimal quantity'
            column: quantity_decimal
    lifecycleCallbacks: {  }

在执行orm命令时,出现如下错误:

 The table with name 'eco_latest.sylius_order' already exists.

配置中这里缺少什么?

编辑:

 $this->addSql('CREATE TABLE SyliusOrder (id INT AUTO_INCREMENT NOT NULL, number VARCHAR(255) DEFAULT NULL, notes LONGTEXT DEFAULT NULL, state VARCHAR(255) NOT NULL, checkout_completed_at DATETIME DEFAULT NULL, items_total INT NOT NULL, adjustments_total INT NOT NULL, total INT NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME DEFAULT NULL, currency_code VARCHAR(3) NOT NULL, locale_code VARCHAR(255) NOT NULL, checkout_state VARCHAR(255) NOT NULL, payment_state VARCHAR(255) NOT NULL, shipping_state VARCHAR(255) NOT NULL, token_value VARCHAR(255) DEFAULT NULL, customer_ip VARCHAR(255) DEFAULT NULL, invoice_no VARCHAR(100) DEFAULT NULL, invoice_file_path VARCHAR(100) DEFAULT NULL, UNIQUE INDEX UNIQ_3458A6D996901F54 (number), PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 COLLATE UTF8_unicode_ci ENGINE = InnoDB');

在我的数据库中创建了syliusorder表。我不确定是否需要进行任何设置来解决此问题。

2 个答案:

答案 0 :(得分:1)

自定义类必须是映射的超类。 使用以下注释:

/**
 * @ORM\MappedSuperclass
 * @ORM\Table(name="sylius_order")
 * @ORM\Entity
 */

答案 1 :(得分:0)

在orm.yml上,将类型从entity更改为mappedSuperclass

Goldco\Entity\Order: type: mappedSuperclass table: sylius_order ...