duanlingzei0170 2018-03-29 07:56
浏览 39
已采纳

Doctrine迁移差异不断创建错误的信息

I am trying to create migrations with doctrine:migrations:diff. the database is now allready in a well enough state, but when i try to at something (such as name shown below) it also keeps trying to change the foreign key.

But it keeps trying to change the FK key:

    public function up(Schema $schema)
    {
    // this up() migration is auto-generated, please modify it to your needs
    $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

    $this->addSql('ALTER TABLE order_manager ADD name VARCHAR(255) NOT NULL');
    $this->addSql('ALTER TABLE orders RENAME INDEX fk_e6ab879d9395c3f3 TO IDX_E52FFDEE9395C3F3');
    $this->addSql('ALTER TABLE orders RENAME INDEX fk_e6ab879dcbe4c936 TO IDX_E52FFDEECBE4C936');
    }

Here is the entity class:

class Orders extends BaseEntity
{ 
/**
 * @ORM\Id
 * @ORM\GeneratedValue
 * @ORM\Column(type="integer")
 */
private $id;

/**
 * @ORM\ManyToOne(targetEntity="App\Entity\Customer", inversedBy="orders", fetch="EAGER")
 * @ORM\JoinColumn(name="customer_id", nullable=true)
 */
private $customer;

/**
 * @ORM\ManyToOne(targetEntity="App\Entity\OrderManager", inversedBy="orders", fetch="EAGER")
 * @ORM\JoinColumn(name="order_manager_id", nullable=true)
 */
private $orderManager;

public function getId()
{
    return $this->id;
}

public function getCustomer(): Customer
{
    return $this->customer;
}

public function setCustomer(Customer $customer)
{
    $this->customer = $customer;
}

public function getOrderManager(): orderManager
{
    return $this->orderManager;
}

public function setOrderManager(orderManager $orderManager)
{
    $this->orderManager = $orderManager;
}
}

When trying to do doctrine:migrations:migrate I get this error

An exception occurred while executing 'ALTER TABLE orders RENAME INDEX fk_e6ab879d9395c3f3 TO IDX_E52FFDEE9395C3F3':

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'INDEX fk_e6ab879d9395c3f3 TO IDX_E52FFDEE9395C3F3' at line 1

  • 写回答

1条回答 默认 最新

  • dpca4790 2018-03-30 10:15
    关注

    It seems like you added those indexes by hand. What you need to do is tell doctrine the name of your indexes using @ORM\Index annotation. http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/annotations-reference.html#annref-index

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题