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) 中,您能否指定新列的位置?


基础教程推荐
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01