13
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Railsでの複数カラムの追加・削除とまとめて行う方法

Posted at

自分用です!

複数のカラム追加していきます。

まずはマイグレーションファイルを作ります。

ターミナル
rails g migration add_columns_to_users

複数のカラムを追加する際、特定のカラムを意識するわけでもない場合は「add_columns」などとしておけばいいでしょう。

class AddColumnsToUsers < ActiveRecord::Migration[5.2]
  def change
    add_column :users, :last_name, :string
    add_column :users, :first_name, :string
  end
end

rails db:migrateをすれば追加される。

13
16
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
13
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?