LoginSignup
1
2

More than 5 years have passed since last update.

Rails column名を変更

Posted at

モデルを作った時にcolumn名を間違えてしまった。
published なのに publishd にしてしまった.

変更方法

$ rails g migration rename_publishd_column_to_books 

実行後

Running via Spring preloader in process 50041
        invoke  active_record
        create    db/migrate/20160601171818_rename_publishd_column_to_books.rb

こんな感じのができるので

20160601171818_rename_publishd_column_to_books.rb を開いて

20160601171818_rename_publishd_column_to_books.rb
class RenamePublishdColumnToBooks < ActiveRecord::Migration
  def change
    rename_column :books, :publishd, :published
  end
end

のように
rename_column :books, :元の名前, :変えたい名前
を追記

$ rails db:migrate

を実行すれば変更ができる。

1
2
1

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
1
2