doctrine:schema:update doesn't respect column

2019-02-07 03:44发布

I have this Entity in Symfony2 :

<?php

namespace Project\UserBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Users
 *
 * @ORM\Table(name="users")
 * @ORM\Entity
 */
class Users
{
    /**
     * @var integer
     *
     * @ORM\Column(name="user_id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $userId;


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

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

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

Then I execute in console :

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

It give me the response :

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

2条回答
相关推荐>>
2楼-- · 2019-02-07 04:07

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

/**
 * @var integer
 *
 * @ORM\Column(type="integer", columnDefinition="INT NOT NULL AFTER `user_id`")
 */
private $superbanana;
查看更多
手持菜刀,她持情操
3楼-- · 2019-02-07 04:25

I don't think this is possible because using Doctrine means that you don't care about how the Table is managed anymore (apparently someone tried it before).

And since you never use MySQL directly, I think there is no utility to specify column orders for Doctrine.

But you can always delete your table so Doctrine will completely rebuild the table, respecting your order.

查看更多
登录 后发表回答