0
0

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 5 years have passed since last update.

テーブルに新しいカラムを追加する方法

0
Last updated at Posted at 2021-03-28

目次

①結論
②カラムを追加するコマンド
③マイグレーションの実行方法

結論

カラムを追加するコマンドを実行し、マイグレーションファイルを実行する。

②カラムを追加するコマンド

rails g migration Addカラム名Toテーブル名 カラム名:データ型
または
rails g migration add_カラム名_toテーブル名 カラム名:データ型

例えば、
postテーブルにuser_idのカラムをinteger型で追加したいときには以下ののように記述する。

rails g migration add_user_id_to_posts user_id:integer

③マイグレーションの実行方法

rails db:migrate

上記を実行する

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?