Symfony/Doctrine Rearranging Database Columns

2019-07-07 08:46发布

When I go to generate a table using the doctrine:schema:update command line, it appears that Doctrine(or Symfony?) wants to throw in a command that rearranges my columns, putting the keys towards the front it would appear. I was wondering if, and more hopefully, where, I can disable this "feature" of the Environment, so when I go to generate my tables, they are kept in the order which I entered them into the orm.

I've looked around for this problem, but it would seem that no one else has it from what I've been able to come up with, and I'm not certain what bundle/part of Doctrine or Symfony I need to alter to have it not desire to rearrange my tables. Any information as to just what part of the bundle would contain this logic, or what option I can add to alter it would be greatly appreciated, as I'm unable to really find anything in the documentation so far.

Update: I did some investigating, and I found an overflow question similar to mine, but not quite. In my case, I'm NOT using new datatypes, and the only columns moved forward are the ones that I've designated as being keys (Primary, or Foreign). The commands that it throws me looks VERY similar to this, except it's doing it to each and every one of my keys.

ALTER TABLE product_price CHANGE price price DECIMAL(10,2) DEFAULT NULL

Doctrine custom type always altering table

Update 2: Additional information as requested: Running MySQL under a .orm.yml format.

The fields it wants to set are always the key fields, and after I change them back to the order I want/need them in, it then feels the need to rearrange the columns again every time.

I don't change anything about the fields; it does this both on initial creations, as well as whenever I need to run the schema update, without any changes to those specific fields.

2条回答
女痞
2楼-- · 2019-07-07 09:06

I think you should use one of these methods on production

  • Run app/console doctrine:schema:update --dump-sql and run sql manualy
  • Use migrations with DoctrineMigrationBundle or something like Liquibase
查看更多
ゆ 、 Hurt°
3楼-- · 2019-07-07 09:21

I did a bit of digging, and I don't think you can have any control over this:

https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Schema/Table.php#L555

Judging by this, the order is PK, FK, and other columns, in that order. It is difficult scanning through pages of raw logic so I may have missed something, but from what I can tell it is not acting on any configuration to decide the order.

查看更多
登录 后发表回答