学说:架构:更新不尊重列顺序

2022-01-03 00:00:00 php mysql symfony doctrine-orm

我在 Symfony2 中有这个 Entity :

I have this Entity in Symfony2 :

<?php

namespace ProjectUserBundleEntity;

use DoctrineORMMapping as ORM;

/**
 * Users
 *
 * @ORMTable(name="users")
 * @ORMEntity
 */
class Users
{
    /**
     * @var integer
     *
     * @ORMColumn(name="user_id", type="integer", nullable=false)
     * @ORMId
     * @ORMGeneratedValue(strategy="IDENTITY")
     */
    private $userId;


    /**
     * @var integer
     *
     * @ORMColumn(name="test", type="integer", nullable=false)
     */
    private $test;
}

我在 {{userId}} 和 {{test}} 之间添加以下行:

I add the following line between {{userId}} and {{test}} :

/**
 * @var integer
 *
 * @ORMColumn(name="superbanana", type="integer", nullable=false)
 */
private $superbanana;

然后我在控制台中执行:

Then I execute in console :

php app/console doctrine:schema:update --dump-sql

它给了我回应:

ALTER TABLE users ADD superbanana INT NOT NULL

**我该怎么办呢?**

**How can I do to have instead ? **

ALTER TABLE users ADD superbanana INT NOT NULL AFTER user_id

推荐答案

如果不想删除/创建表,可以使用 @columnDefinition 属性并自己定义列定义.

If you don't want to drop/create the table, you can use @columnDefinition attribute and define the column definition yourself.

/**
 * @var integer
 *
 * @ORMColumn(type="integer", columnDefinition="INT NOT NULL AFTER `user_id`")
 */
private $superbanana;

相关文章