lepix lepix - 5 months ago 36
PHP Question

doctrine:schema:update doesn't respect column order

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

Answer

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