在Rails迁移(MySQL)中,您可以指定新列应位于的位置吗? [英] In a Rails Migration (MySQL), can you specify what position a new column should be?

查看:58
本文介绍了在Rails迁移(MySQL)中,您可以指定新列应位于的位置吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我通过My​​SQL添加一列,则可以使用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?

推荐答案

在Rails 2.3.6+中,现在可以通过传递:after参数

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)中,您可以指定新列应位于的位置吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆