LoginSignup
28
26

More than 5 years have passed since last update.

Rails migrationでカラムを追加する場所を指定する方法

Posted at

まずはmigrationファイルを作成する。

r g migration AddColumnToUsers work_time:time
invoke  active_record
create  db/migrate/20131202155637_add_column_to_users.rb

作成されたファイルを開く。
add_columnの行の最後に、:after => :column_nameを追記。

db/migrate/20131202155637_add_column_to_users.rb
class AddColumnToUsers < ActiveRecord::Migration
  def change
    add_column :users, :work_time, :time, :after => :necessary_time
  end
end

で、

rake db:migrate
28
26
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
28
26