Doctrine: schema: update does not respect column order

I have 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 launch the console:

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

He gave me the answer:

 ALTER TABLE users ADD superbanana INT NOT NULL 

** How can i do this? **

 ALTER TABLE users ADD superbanana INT NOT NULL AFTER user_id 
+7
php mysql symfony doctrine2
source share
2 answers

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

 /** * @var integer * * @ORM\Column(type="integer", columnDefinition="INT NOT NULL AFTER `user_id`") */ private $superbanana; 
+12
source share

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

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

But you can always delete your table so that Doctrine completely rebuilds the table, keeping your order.

+1
source share

All Articles