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

时间:2018-03-29 07:56:08

标签: php symfony doctrine-orm

我正在尝试使用doctrine创建迁移:migrations:diff。 数据库现在已经处于足够好的状态,但是当我尝试某些东西(例如下面显示的名称)时,它也会不断尝试更改外键。

但它一直试图改变FK键:

    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');
    }

这是实体类:

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

尝试做教义时:迁移:迁移我收到此错误

执行' ALTER TABLE命令时发生异常RENAME INDEX fk_e6ab879d9395c3f3 TO IDX_E52FFDEE9395C3F3':

SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误;检查与您的MariaDB服务器版本对应的手册,以便在#" INDEX fk_e6ab879d9395c3f3 TO IDX_E52FFDEE9395C3F3'附近使用正确的语法。在第1行

1 个答案:

答案 0 :(得分:0)

好像你手动添加了这些索引。您需要做的是使用name注释告诉您的索引的@ORM\Indexhttp://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/annotations-reference.html#annref-index