简体   繁体   English

Symfony/Doctrine 重新排列数据库列

[英]Symfony/Doctrine Rearranging Database Columns

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.当我使用 doctrine:schema:update 命令行生成表格时,似乎 Doctrine(或 Symfony?)想要输入一个重新排列我的列的命令,将键放在它会出现的前面。 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.我想知道是否,更希望在哪里,我可以禁用环境的这个“功能”,所以当我去生成我的表时,它们会按照我将它们输入到 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.我已经环顾四周寻找这个问题,但似乎没有其他人从我能够想出的东西中得到它,而且我不确定我需要更改为 Doctrine 或 Symfony 的哪个包/部分它不想重新排列我的桌子。 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 Doctrine 自定义类型总是改变表格

Update 2: Additional information as requested: Running MySQL under a .orm.yml format.更新 2:按要求提供附加信息:以 .orm.yml 格式运行 MySQL。

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.它在初始创建时以及每当我需要运行架构更新时都这样做,而无需对这些特定字段进行任何更改。

I did a bit of digging, and I don't think you can have any control over this.我做了一些挖掘,我认为你无法控制它。 See getColumns() [1] [2]参见 getColumns() [1] [2]

Judging by this, the order is PK, FK, and other columns, in that order.以此判断,顺序是PK、FK、其他栏目,依次为。 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.扫描原始逻辑页面很困难,所以我可能错过了一些东西,但据我所知,它不会根据任何配置来决定顺序。

[1] (at the time of the answer; Nov 2013) https://github.com/doctrine/dbal/blob/5ffb052a2e622908c988f79e9a099f5d64f40b34/lib/Doctrine/DBAL/Schema/Table.php#L555 [1](回答时;2013 年 11 月) https://github.com/doctrine/dbal/blob/5ffb052a2e622908c988f79e9a099f5d64f40b34/lib/Doctrine/DBAL/Schema/Table.php#L555

[2] (updated line number; June 2020) https://github.com/doctrine/dbal/blob/2.10.x/lib/Doctrine/DBAL/Schema/Table.php#L595 [2](更新行号;2020 年 6 月) https://github.com/doctrine/dbal/blob/2.10.x/lib/Doctrine/DBAL/Schema/Table.php#L595

I think you should use one of these methods on production我认为您应该在生产中使用这些方法之一

  • Run app/console doctrine:schema:update --dump-sql and run sql manualy运行 app/console 指令:schema:update --dump-sql 并手动运行 sql
  • Use migrations with DoctrineMigrationBundle or something like Liquibase将迁移与 DoctrineMigrationBundle 或 Liquibase 之类的东西一起使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM