In a Rails Migration (MySQL), can you specify what position a new column should be?(在 Rails 迁移 (MySQL) 中,您能否指定新列的位置?)
问题描述
如果我通过 MySQL 添加列,我可以指定该列在表中的哪个位置使用 AFTER 修饰符.但如果我通过 Rails 迁移执行 add_column,则该列将在表的末尾创建.
If I'm adding a column via MySQL, I can specify where in the table that column will be using the AFTER modifier. But if I do the add_column via a Rails migration, the column will be created at the end of the table.
rails 迁移是否有任何功能可以指定添加列的位置?
Is there any functionality for rails migrations to specify the position of an added column?
推荐答案
现在可以通过传递 :after 参数在 Rails 2.3.6+ 中实现这一点
This is now possible in Rails 2.3.6+ by passing the :after parameter
https://rails.lighthouseapp.com/projects/8994/tickets/3286-patch-add-support-for-mysql-column-positioning-to-migrations
对于没有看到拥有此功能的优势的每个人:您从不在 ORM 之外查看您的数据库吗?如果我在任何类型的 UI 中查看,我喜欢将外键、状态列、标志等所有内容组合在一起.这不会影响应用程序,但肯定会加快我查看数据的能力.
To everyone that doesn't see the advantage in having this feature: do you never look at your database outside of the ORM? If I'm viewing in any sort of UI, I like having things like foreign keys, status columns, flags, etc, all grouped together. This doesn't impact the application, but definitely speeds up my ability to review data.
这篇关于在 Rails 迁移 (MySQL) 中,您能否指定新列的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Rails 迁移 (MySQL) 中,您能否指定新列的位置?


- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- SQL 临时表问题 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01