【发布时间】:2018-09-07 07:00:27
【问题描述】:
我正在尝试向订单表添加一个新字段。但最重要的是抛出错误,比如表已经存在。我试图关注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 表是在我的数据库中创建的。我不确定是否需要进行任何设置来解决此问题。
【问题讨论】:
-
尝试删除行
@ORM\Table(name="sylius_order") -
如果我删除了新的 SyliusOrder 表,将会创建。我想编辑 sylius_order
-
你真的试过了吗? Doctrine 默认以snake_case命名保存新表
-
@Dr.X:是的,添加的迁移脚本有问题。请参考