Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 827
lepix Avatar asked Jun 10 '14 18:06

lepix


1 Answers

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;
like image 105
b.b3rn4rd Avatar answered Nov 14 '22 17:11

b.b3rn4rd