问题描述
如果我通过 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) 中,您能否指定新列的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!